Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ Version 2.1.7

To be released.

### @fedify/init

- Fixed `fedify init` generating Astro projects for Bun with the Node.js
adapter and `astro preview`, which could fail to run correctly on Bun.
Astro + Bun projects now use *@nurodev/astro-bun* and run the built
Bun server entry point instead. [[#707]]

[#707]: https://github.com/fedify-dev/fedify/pull/707


Version 2.1.6
-------------
Expand Down
64 changes: 57 additions & 7 deletions deno.lock

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

58 changes: 50 additions & 8 deletions examples/astro/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ A comprehensive example of building a federated server application using
[Fedify] with [Astro] via the [`@fedify/astro`] package. This sample
demonstrates how to create an ActivityPub-compatible federated social media
server that can interact with other federated platforms like Mastodon, Pleroma,
and other ActivityPub implementations. It supports both [Deno] and [Node.js]
runtimes.
and other ActivityPub implementations. It supports [Deno], [Node.js], and
[Bun] runtimes.

[Fedify]: https://fedify.dev
[Astro]: https://astro.build/
[`@fedify/astro`]: https://jsr.io/@fedify/astro
[Deno]: https://deno.com/
[Node.js]: https://nodejs.org/
[Bun]: https://bun.sh/


Features
Expand All @@ -30,7 +31,8 @@ Features
- **Inbox Processing**: Real-time activity processing from federated instances
- **Content Negotiation**: Same routes serve HTML for browsers and ActivityPub
JSON for federated clients
- **Dual Runtime**: Supports both Deno and Node.js via separate Astro configs
- **Three Runtimes**: Supports Deno, Node.js, and Bun via separate Astro
configs
- **TypeScript**: Full type safety throughout the application


Expand All @@ -40,8 +42,10 @@ How it works
- *astro.config.deno.ts* registers `fedifyIntegration()` to configure Vite's
SSR settings for Fedify compatibility, and uses `@deno/astro-adapter` to
run on Deno.
- *astro.config.node.ts* registers `fedifyIntegration()` without any adapter
for Node.js.
- *astro.config.node.ts* registers `fedifyIntegration()` and uses
`@astrojs/node` for Node.js.
- *astro.config.bun.ts* registers `fedifyIntegration()` and uses
`@nurodev/astro-bun` for Bun.
- *src/lib/store.ts* defines in-memory stores for key pairs, follower
relationships, and posts.
- *src/lib/federation.ts* sets up the full `Federation` instance with:
Expand Down Expand Up @@ -111,6 +115,23 @@ pnpm dev

This uses *astro.config.node.ts* as the configuration file.

### Bun

To run the dev server with Bun:

~~~~ command
bun run dev:bun
~~~~

This uses *astro.config.bun.ts* as the configuration file.

To build and run the Bun server bundle:

~~~~ command
bun run build:bun
bun run preview:bun
~~~~

### Testing

The application will be available at <http://localhost:4321/>.
Expand Down Expand Up @@ -139,6 +160,8 @@ Example usage scenarios
deno task dev
# or for Node.js
pnpm dev
# or for Bun
bun run dev:bun
~~~~

2. Visit the home page at <http://localhost:4321/> to see the demo account
Expand Down Expand Up @@ -216,13 +239,13 @@ Using as a template
-------------------

If you are creating a new project based on this example, you only need the
configuration file for your target runtime. Delete the unused one and rename
configuration file for your target runtime. Delete the unused ones and rename
the one you keep to *astro.config.ts*:
Comment thread
dahlia marked this conversation as resolved.

### For Deno

~~~~ command
rm astro.config.node.ts
rm astro.config.node.ts astro.config.bun.ts
mv astro.config.deno.ts astro.config.ts
~~~~

Expand All @@ -241,7 +264,7 @@ Then remove the `--config` flags from *deno.json* tasks:
### For Node.js

~~~~ command
rm astro.config.deno.ts
rm astro.config.deno.ts astro.config.bun.ts
mv astro.config.node.ts astro.config.ts
~~~~

Expand All @@ -257,6 +280,25 @@ Then remove the `--config` flags from *package.json* scripts:
}
~~~~

### For Bun

~~~~ command
rm astro.config.deno.ts astro.config.node.ts
mv astro.config.bun.ts astro.config.ts
~~~~

Then update *package.json* scripts to use Bun's SSR entry point after build:

~~~~ json
{
"scripts": {
"dev": "bunx astro dev",
"build": "bunx astro build",
"preview": "bun ./dist/server/entry.mjs"
}
}
~~~~


Links
-----
Expand Down
12 changes: 12 additions & 0 deletions examples/astro/astro.config.bun.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import bun from "@nurodev/astro-bun";
import { fedifyIntegration } from "@fedify/astro";
import { defineConfig } from "astro/config";

// https://astro.build/config
export default defineConfig({
integrations: [fedifyIntegration()],
output: "server",
adapter: bun(),
server: { host: true, allowedHosts: true },
security: { allowedDomains: [{}] },
Comment thread
dahlia marked this conversation as resolved.
Comment thread
dahlia marked this conversation as resolved.
Comment thread
dahlia marked this conversation as resolved.
});
6 changes: 5 additions & 1 deletion examples/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
"scripts": {
"dev": "astro dev --config astro.config.node.ts",
"build": "astro build --config astro.config.node.ts",
"preview": "astro preview --config astro.config.node.ts"
"preview": "astro preview --config astro.config.node.ts",
"dev:bun": "bunx astro dev --config astro.config.bun.ts",
"build:bun": "bunx astro build --config astro.config.bun.ts",
"preview:bun": "bun ./dist/server/entry.mjs"
},
"dependencies": {
"@astrojs/node": "^9.5.4",
"@deno/astro-adapter": "^0.3.2",
"@fedify/astro": "workspace:^",
"@fedify/fedify": "workspace:^",
"@fedify/vocab": "workspace:^",
"@nurodev/astro-bun": "^2.1.2",
"astro": "catalog:"
Comment thread
dahlia marked this conversation as resolved.
}
}
35 changes: 33 additions & 2 deletions packages/astro/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,12 @@ export const onRequest = fedifyMiddleware(
For Deno users
--------------

If you are using Deno, you should import `@deno/vite-adapter` in
If you are using Deno, you should import `@deno/astro-adapter` in
*astro.config.mjs* and use it as the adapter:

~~~~ typescript
import { defineConfig } from "astro/config";
import { fedifyIntegration } from "@fedify/astro";
import deno from "@deno/vite-adapter";
import deno from "@deno/astro-adapter";

export default defineConfig({
Expand All @@ -82,6 +81,38 @@ instead of `astro`:
~~~~


For Bun users
-------------

If you are using Bun, install `@nurodev/astro-bun` and configure it as the
Astro adapter:

~~~~ typescript
import { defineConfig } from "astro/config";
import { fedifyIntegration } from "@fedify/astro";
import bun from "@nurodev/astro-bun";

export default defineConfig({
integrations: [fedifyIntegration()],
output: "server",
adapter: bun(),
});
~~~~

Then use Bun to start Astro in development, and run the generated server entry
point after building for preview or production:

~~~~ json
{
"scripts": {
"dev": "bunx astro dev",
"build": "bunx astro build",
"preview": "bun ./dist/server/entry.mjs"
}
}
~~~~


How it works
------------

Expand Down
Loading
Loading