Bun integration
Это содержимое пока не доступно на вашем языке.
The Aspire Bun hosting integration enables you to run Bun applications alongside your other Aspire resources in the app host. Bun apps participate in the same service discovery, health checks, OpenTelemetry export, and Aspire dashboard support as the rest of your solution.
Hosting integration
Section titled “Hosting integration”To access the Bun hosting APIs in your AppHost project, install the 📦 CommunityToolkit.Aspire.Hosting.Bun NuGet package:
aspire add communitytoolkit-bunAspire CLI интерактивен; выберите подходящий результат поиска при запросе:
Select an integration to add:
> communitytoolkit-bun (CommunityToolkit.Aspire.Hosting.Bun)> Other results listed as selectable options...#:package CommunityToolkit.Aspire.Hosting.Bun@*<PackageReference Include="CommunityToolkit.Aspire.Hosting.Bun" Version="*" />Add Bun app
Section titled “Add Bun app”Add a Bun application to your app host using the AddBunApp extension method:
var builder = DistributedApplication.CreateBuilder(args);
var bunApp = builder.AddBunApp("bun-api", "../bun-app") .WithHttpEndpoint(port: 3000, env: "PORT");
builder.AddProject<Projects.ExampleProject>("apiservice") .WithReference(bunApp);
builder.Build().Run();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.
Specify a custom entrypoint
Section titled “Specify a custom entrypoint”Pass an explicit entrypoint path to run a different script:
var builder = DistributedApplication.CreateBuilder(args);
var bunApp = builder.AddBunApp("bun-api", "../bun-app", "server.ts") .WithHttpEndpoint(port: 3000, env: "PORT");
builder.Build().Run();Install packages before startup
Section titled “Install packages before startup”Call WithBunPackageInstallation to run bun install before starting the application:
var builder = DistributedApplication.CreateBuilder(args);
var bunApp = builder.AddBunApp("bun-api", "../bun-app") .WithBunPackageInstallation() .WithHttpEndpoint(port: 3000, env: "PORT");
builder.Build().Run();Configure HTTP endpoints
Section titled “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:
var builder = DistributedApplication.CreateBuilder(args);
var bunApp = builder.AddBunApp("bun-api", "../bun-app") .WithHttpEndpoint(port: 3000, env: "PORT");
builder.Build().Run();Your Bun application reads the PORT variable at startup:
const server = Bun.serve({ port: process.env.PORT || 3000, fetch(request) { return new Response("Hello from Bun!"); },});
console.log(`Server listening on port ${server.port}`);