Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
# Framework and platform integrations. Hong Minhee maintains all of
# them; ChanHaeng Lee co-maintains the ones he contributed to, and
# leads the Nuxt integration.
/packages/adonisjs/ @scammo @dahlia
Comment thread
scammo marked this conversation as resolved.
Outdated
/packages/astro/ @2chanhaeng @dahlia
/packages/cfworkers/ @dahlia @2chanhaeng
/packages/elysia/ @dahlia
Expand Down
2 changes: 2 additions & 0 deletions .hongdown.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ exclude = [
[heading]
sentence_case = true
proper_nouns = [
"@fedify/adonisjs",
"@fedify/cli",
"@fedify/elysia",
"@fedify/express",
Expand All @@ -45,6 +46,7 @@ proper_nouns = [
"ActivityKit",
"ActivityPub",
"ActivityStreams",
"AdonisJS",
"Akkoma",
"Biome",
"BotKit",
Expand Down
12 changes: 12 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ To be released.
[#934]: https://github.com/fedify-dev/fedify/pull/934
[#968]: https://github.com/fedify-dev/fedify/pull/968

### @fedify/adonisjs

- Added the new *@fedify/adonisjs* package, an integration for the AdonisJS
framework. It provides a server middleware that mounts a `Federation`
inside an AdonisJS application, a service provider that owns the
federation's lifecycle, a `node ace configure` hook that scaffolds
*config/fedify.ts* and the federation preload files, and a `ctx.federation`
request context. The package targets Node.js and is published to npm only.
[[#139]]

[#139]: https://github.com/fedify-dev/fedify/issues/139

### @fedify/astro

- Added and continuously tested support for Astro 6 and 7 while retaining
Expand Down
11 changes: 11 additions & 0 deletions changes.d/adonisjs/adonisjs-integration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
links:
'#139': https://github.com/fedify-dev/fedify/issues/139
---
- Added the new *@fedify/adonisjs* package, an integration for the AdonisJS
framework. It provides a server middleware that mounts a `Federation`
inside an AdonisJS application, a service provider that owns the
federation's lifecycle, a `node ace configure` hook that scaffolds
*config/fedify.ts* and the federation preload files, and a `ctx.federation`
request context. The package targets Node.js and is published to npm only.
[[#139]]
Comment thread
scammo marked this conversation as resolved.
Outdated
4 changes: 4 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"aarch64",
"activitypub",
"activitystreams",
"adonis",
"adonisjs",
"aitertools",
"amqp",
"amqplib",
Expand All @@ -18,6 +20,7 @@
"cfworker",
"cfworkers",
"codegen",
"codemods",
"compactable",
"cryptosuite",
"decorrelated",
Expand Down Expand Up @@ -64,6 +67,7 @@
"lifecycles",
"litepub",
"logtape",
"lucid",
"lume",
"lumocs",
"metas",
Expand Down
1 change: 1 addition & 0 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
"./packages"
],
"exclude": [
"./packages/adonisjs/**",
"./packages/init/src/templates/**",
"./packages/next/**"
]
Expand Down
89 changes: 89 additions & 0 deletions docs/manual/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,95 @@ sequenceDiagram
[content negotiation]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Content_negotiation


AdonisJS
--------

*This API is available since Fedify 2.4.0.*

[AdonisJS] is a batteries-included TypeScript framework for Node.js, with its
own IoC container, service providers and CLI. The *@fedify/adonisjs* package
integrates Fedify with AdonisJS. It requires Node.js 24 or later, matching
the `engines` requirement `@adonisjs/core` itself declares, and targets
Node.js only: AdonisJS documents Node.js as its sole runtime, so the package
is published to npm and not to JSR, and is not tested on Deno or Bun.

::: code-group

~~~~ sh [npm]
node ace add @fedify/adonisjs
~~~~

~~~~ sh [pnpm]
node ace add --package-manager=pnpm @fedify/adonisjs
~~~~

~~~~ sh [Yarn]
node ace add --package-manager=yarn @fedify/adonisjs
~~~~

:::

Unlike the other integrations, there is nothing to wire up by hand. The
`configure` hook that `node ace add` runs registers the service provider and the
server middleware, and writes *config/fedify.ts*, *start/federation.ts* and
*app/federation/main.ts*.

Set the canonical origin in *config/fedify.ts*—Fedify mints actor URIs from it,
so it has to be the address remote servers can reach:

~~~~ typescript twoslash
// config/fedify.ts
import { defineConfig } from "@fedify/adonisjs";

export default defineConfig({
origin: "https://example.com", // [!code highlight]
});
~~~~

Then register dispatchers on the builder that
*@fedify/adonisjs/services/builder* exports. The generated
*start/federation.ts* preload file imports this module, which AdonisJS loads
after every service provider has booted—so dispatchers may use Lucid models and
anything else the container provides:

~~~~ typescript twoslash
// app/federation/main.ts
import federation from "@fedify/adonisjs/services/builder";
import { Person } from "@fedify/vocab";

federation.setActorDispatcher(
"/actors/{identifier}",
(ctx, identifier) => { // [!code highlight]
return new Person({ // [!code highlight]
id: ctx.getActorUri(identifier), // [!code highlight]
preferredUsername: identifier, // [!code highlight]
}); // [!code highlight]
},
);
~~~~

Every request then carries a Fedify `RequestContext` as `ctx.federation`, so an
ordinary controller can mint URIs, look remote objects up, or send activities:

~~~~ typescript twoslash
import "@fedify/adonisjs/types";
import type { HttpContext } from "@adonisjs/core/http";
// ---cut-before---
export default class ActorsController {
async show({ params, federation }: HttpContext) {
return { actor: federation.getActorUri(params.identifier).href };
}
}
~~~~

The middleware is registered in the *server* middleware stack rather than the
router stack, because Fedify serves paths the AdonisJS router knows nothing
about—*/.well-known/webfinger* among them—and because HTTP Signature
verification needs the request body before the body parser consumes it.

[AdonisJS]: https://adonisjs.com/


Express
-------

Expand Down
4 changes: 3 additions & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"devDependencies": {
"@adonisjs/core": "catalog:",
"@braintree/sanitize-url": "^7.1.2",
"@cloudflare/workers-types": "catalog:",
"@deno/kv": "^0.8.4",
"@fedify/adonisjs": "workspace:^",
"@fedify/amqp": "workspace:^",
"@fedify/astro": "workspace:^",
"@fedify/backfill": "workspace:^",
Expand All @@ -17,8 +19,8 @@
"@fedify/koa": "workspace:^",
"@fedify/lint": "workspace:^",
"@fedify/mysql": "workspace:^",
"@fedify/netlify": "workspace:^",
"@fedify/nestjs": "workspace:^",
"@fedify/netlify": "workspace:^",
"@fedify/next": "workspace:^",
"@fedify/postgres": "workspace:^",
"@fedify/redis": "workspace:^",
Expand Down
Loading