diff --git a/src/frontend/src/content/docs/integrations/frameworks/bun-apps.mdx b/src/frontend/src/content/docs/integrations/frameworks/bun-apps.mdx index 3a56b9c67..a3830f6ce 100644 --- a/src/frontend/src/content/docs/integrations/frameworks/bun-apps.mdx +++ b/src/frontend/src/content/docs/integrations/frameworks/bun-apps.mdx @@ -1,17 +1,13 @@ --- title: Bun integration -seoTitle: Bun integration for Aspire AppHost (Community Toolkit) -description: Learn how to use the Aspire Community Toolkit Bun hosting integration to orchestrate Bun applications alongside other resources in the Aspire app host. +description: Learn how to use the Aspire Bun hosting integration to orchestrate Bun applications alongside other resources in the Aspire app host. --- -import { Badge } from '@astrojs/starlight/components'; - +import { Aside, Tabs, TabItem } from '@astrojs/starlight/components'; import { Image } from 'astro:assets'; import InstallPackage from '@components/InstallPackage.astro'; import bunIcon from '@assets/icons/bun-icon.png'; - - Bun logo +As of Aspire 13.4, Bun hosting support is available in the official `Aspire.Hosting.JavaScript` package as `BunAppResource`. The `CommunityToolkit.Aspire.Hosting.Bun` package from the Community Toolkit is deprecated — use `Aspire.Hosting.JavaScript` and `AddBunApp` / `addBunApp` for Aspire 13.4+ applications. + ## Hosting integration -To access the Bun hosting APIs in your [`AppHost`](/get-started/app-host/) project, install the [📦 CommunityToolkit.Aspire.Hosting.Bun](https://www.nuget.org/packages/CommunityToolkit.Aspire.Hosting.Bun) NuGet package: +To access the Bun hosting APIs in your [`AppHost`](/get-started/app-host/) project, install the [📦 Aspire.Hosting.JavaScript](https://www.nuget.org/packages/Aspire.Hosting.JavaScript) NuGet package: - + ### Add Bun app -Add a Bun application to your app host using the `AddBunApp` extension method: +Add a Bun application to your app host using the `AddBunApp` / `addBunApp` extension method: + + + ```csharp title="C# — AppHost.cs" var builder = DistributedApplication.CreateBuilder(args); @@ -49,17 +48,37 @@ builder.AddProject("apiservice") builder.Build().Run(); ``` -`AddBunApp` requires: + + + +```typescript title="TypeScript — apphost.mts" +import { createBuilder } from "./.aspire/modules/aspire.mjs"; + +const builder = await createBuilder(); + +const bunApp = await builder.addBunApp("bun-api", "../bun-app"); +await bunApp.withHttpEndpoint({ port: 3000, env: "PORT" }); + +await builder.build().run(); +``` + + + + +`AddBunApp` / `addBunApp` requires: - **name**: The name of the resource in the Aspire dashboard. - **workingDirectory**: The path to the directory containing your Bun application, relative to the AppHost project. -By default, the integration looks for an `index.ts` file as the entrypoint. +By default, the integration looks for an `index.ts` file as the entrypoint. The resource is typed as `BunAppResource`. ### Specify a custom entrypoint Pass an explicit entrypoint path to run a different script: + + + ```csharp title="C# — AppHost.cs" var builder = DistributedApplication.CreateBuilder(args); @@ -69,32 +88,20 @@ var bunApp = builder.AddBunApp("bun-api", "../bun-app", "server.ts") builder.Build().Run(); ``` -### Install packages before startup - -Call `WithBunPackageInstallation` to run `bun install` before starting the application: - -```csharp title="C# — AppHost.cs" -var builder = DistributedApplication.CreateBuilder(args); + + -var bunApp = builder.AddBunApp("bun-api", "../bun-app") - .WithBunPackageInstallation() - .WithHttpEndpoint(port: 3000, env: "PORT"); - -builder.Build().Run(); +```typescript title="TypeScript — apphost.mts" +const bunApp = await builder.addBunApp("bun-api", "../bun-app", { entrypoint: "server.ts" }); +await bunApp.withHttpEndpoint({ port: 3000, env: "PORT" }); ``` -### Configure HTTP endpoints - -Bun applications typically read the port from an environment variable. Use `WithHttpEndpoint` to declare the HTTP endpoint and bind it to a named environment variable: - -```csharp title="C# — AppHost.cs" -var builder = DistributedApplication.CreateBuilder(args); + + -var bunApp = builder.AddBunApp("bun-api", "../bun-app") - .WithHttpEndpoint(port: 3000, env: "PORT"); +### Configure HTTP endpoints -builder.Build().Run(); -``` +Bun applications typically read the port from an environment variable. Use `WithHttpEndpoint` / `withHttpEndpoint` to declare the HTTP endpoint and bind it to a named environment variable: Your Bun application reads the `PORT` variable at startup: @@ -111,8 +118,8 @@ console.log(`Server listening on port ${server.port}`); ## See also -- [📦 CommunityToolkit.Aspire.Hosting.Bun](https://www.nuget.org/packages/CommunityToolkit.Aspire.Hosting.Bun) +- [📦 Aspire.Hosting.JavaScript](https://www.nuget.org/packages/Aspire.Hosting.JavaScript) +- [JavaScript hosting integration](/integrations/frameworks/javascript/) - [Bun documentation](https://bun.sh/docs) -- [Aspire Community Toolkit](https://github.com/CommunityToolkit/Aspire) - [Aspire integrations overview](/integrations/overview/) - [Aspire GitHub repo](https://github.com/microsoft/aspire) diff --git a/src/frontend/src/content/docs/integrations/frameworks/javascript.mdx b/src/frontend/src/content/docs/integrations/frameworks/javascript.mdx index ec8bf83cd..b3c448581 100644 --- a/src/frontend/src/content/docs/integrations/frameworks/javascript.mdx +++ b/src/frontend/src/content/docs/integrations/frameworks/javascript.mdx @@ -39,6 +39,7 @@ The integration exposes a number of app resource types: - `NodeAppResource`: Added with `AddNodeApp` / `addNodeApp` for running specific JavaScript files with Node.js - `ViteAppResource`: Added with `AddViteApp` / `addViteApp` for Vite applications with Vite-specific defaults - `NextJsAppResource`: Added with `AddNextJsApp` / `addNextJsApp` for Next.js applications with Next.js-specific run and publish defaults +- `BunAppResource`: Added with `AddBunApp` / `addBunApp` for applications running on the [Bun](https://bun.sh/) runtime — see the [Bun integration](/integrations/frameworks/bun-apps/) for details ## Framework examples