This is a simple example of how to integrate Fedify into an AdonisJS application. It publishes one actor, accepts follows, and serves an HTML profile page at the very same URL that remote servers read the ActivityPub actor document from.
The example wires up Fedify the way the @fedify/adonisjs package is meant to
be used:
- The service provider,
@fedify/adonisjs/fedify_provider, is registered in adonisrc.ts. It builds theFederationand constructs the middleware from it and the configuration. - The Fedify server middleware,
@fedify/adonisjs/fedify_middleware, is first in theserverstack in start/kernel.ts—wherenode ace configureputs it—so it runs before route matching, before the body parser, and before anything that could rewrite theAcceptheader it negotiates on. - config/fedify.ts sets the canonical origin with
defineConfig(). - Dispatchers are registered on the builder exported by
@fedify/adonisjs/services/builder, from the start/federation.ts preload file. ctx.federationis available in controllers and routes.
One thing here deviates from what node ace configure @fedify/adonisjs
scaffolds: start/env.ts declares PUBLIC_URL as optional rather than
required, so that the example runs with no configuration at all.
config/fedify.ts then falls back to the address the server actually bound.
A real deployment sets PUBLIC_URL and can require it, as the scaffold does.
-
Copy .env.example to .env:
cp .env.example .env
-
Install dependencies and start the server:
pnpm install pnpm start
The application listens on http://localhost:3333 and the actor is
demo.[!NOTE]
node ace servefalls back to a free random port when 3333 is already taken, and it prints the address it settled on. Use that port in the commands below; withPUBLIC_URLunset the actor URIs follow it automatically. -
Open http://localhost:3333/. Browsers asking for HTML at http://localhost:3333/users/demo get the profile page:
curl -H 'Accept: text/html' http://localhost:3333/users/demoServers asking for ActivityPub get the actor document instead:
curl -H 'Accept: application/activity+json' \ http://localhost:3333/users/demo | jq
The Fedify CLI can look the actor up the same way, and
-asigns the request the way a remote server would:pnpx @fedify/cli lookup http://localhost:3333/users/demo -a
-
Localhost is not reachable from other servers, so to actually exchange activities you need a public address. The Fedify CLI provides one:
pnpx @fedify/cli tunnel 3333
Put the tunnel URL into .env as
PUBLIC_URL, restartpnpm start, and search for@demo@<the-tunnel-host>from any Mastodon-compatible server.