Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions playground/AspireWithBun/BunFrontend/bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions playground/AspireWithBun/BunFrontend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "bunfrontend",
"version": "1.0.0",
"type": "module",
"private": true,
"scripts": {
"start": "bun server.ts"
},
"dependencies": {
"ms": "^2.1.3"
},
"devDependencies": {
"chalk": "^5.6.2"
}
}
18 changes: 18 additions & 0 deletions playground/AspireWithBun/BunFrontend/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Minimal Bun HTTP server used by the AspireWithBun playground and BunFunctionalTests.
// Distinguishes between direct invocation (`bun server.ts`) and package-script invocation
// (`bun run start`) by checking `npm_lifecycle_event`, which Bun sets when running a script.

const port = Number(process.env.PORT ?? 3000);
const isScriptRun = process.env.npm_lifecycle_event !== undefined;
const greeting = isScriptRun ? "Hello from bun script!" : "Hello from bun!";

const server = Bun.serve({
port,
fetch(_req) {
return new Response(greeting, {
headers: { "Content-Type": "text/plain" },
});
},
});

console.log(`Bun server listening on http://${server.hostname}:${server.port}`);
24 changes: 24 additions & 0 deletions playground/AspireWithBun/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# AspireWithBun

A minimal Aspire **TypeScript AppHost** that hosts a [Bun](https://bun.com/) HTTP server two different ways:

| Resource | API | Behavior |
|-------------|------------------------------------------------------------|---------------------------------------------------|
| `bunapp` | `addBunApp("bunapp", "./BunFrontend", "server.ts")` | Runs `bun server.ts` directly. |
| `bunscript` | `addBunApp(...).withRunScript("start")` | Runs `bun run start` against the `start` script. |

Both resources serve a simple `text/plain` greeting and use `Bun.serve`.

## Prerequisites

- [Aspire CLI](https://learn.microsoft.com/dotnet/aspire/) on PATH
- [Bun](https://bun.com/docs/installation) on PATH
- Node.js (used to host the TypeScript AppHost itself)

## Run

```bash
aspire run
```

The CLI generates the `.aspire/modules/` TypeScript bindings the first time it runs, then starts the AppHost. Open the URL listed for `bunapp` or `bunscript` in the dashboard. Each returns a different greeting so you can confirm which entry path served the response.
24 changes: 24 additions & 0 deletions playground/AspireWithBun/apphost.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Aspire TypeScript AppHost — exercises the Aspire.Hosting.JavaScript `AddBunApp` API.
// Run with: aspire run
// Publish with: aspire publish (emits Docker Compose + Dockerfiles using oven/bun:1)

import { createBuilder } from './.aspire/modules/aspire.mjs';

const builder = await createBuilder();

await builder.addDockerComposeEnvironment("compose");

// Direct file execution: `bun server.ts`
await builder
.addBunApp("bunapp", "./BunFrontend", "server.ts")
.withHttpEndpoint({ env: "PORT" })
.withExternalHttpEndpoints();

// Package-script execution: `bun run start` (uses the `start` script in package.json)
await builder
.addBunApp("bunscript", "./BunFrontend", "server.ts")
.withRunScript("start")
.withHttpEndpoint({ env: "PORT" })
.withExternalHttpEndpoints();

await builder.build().run();
10 changes: 10 additions & 0 deletions playground/AspireWithBun/aspire.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"appHost": {
"path": "apphost.mts",
"language": "typescript/nodejs"
},
"packages": {
"Aspire.Hosting.JavaScript": "",
"Aspire.Hosting.Docker": ""
}
}
Loading
Loading