| 1 | // routes/federation.js — publieke Cirkels-endpoints (v1, publicatie-kant).
|
|---|
| 2 | //
|
|---|
| 3 | // GET /.klonkt/actor.json — ActivityStreams-actor + Ed25519-pubkey
|
|---|
| 4 | // GET /.klonkt/outbox.json — publieke posts als AS Create-objecten,
|
|---|
| 5 | // getekend via de Klonkt-Signature-header
|
|---|
| 6 | //
|
|---|
| 7 | // Site-agnostisch en zonder auth — alleen lezen. Zie docs/cirkels-v1-spec.md.
|
|---|
| 8 |
|
|---|
| 9 | import express from 'express';
|
|---|
| 10 | import { buildActor, buildOutbox, signBody } from '../services/CircleFederation.js';
|
|---|
| 11 | import { getTenancy } from '../services/SettingsService.js';
|
|---|
| 12 |
|
|---|
| 13 | const router = express.Router();
|
|---|
| 14 |
|
|---|
| 15 | function baseUrl(req) {
|
|---|
| 16 | const b = process.env.PUBLIC_BASE_URL || `${req.protocol}://${req.get('host')}`;
|
|---|
| 17 | return b.replace(/\/+$/, '');
|
|---|
| 18 | }
|
|---|
| 19 |
|
|---|
| 20 | router.get('/.klonkt/actor.json', (req, res) => {
|
|---|
| 21 | // Cirkels = solo-naar-solo; hubs publiceren geen federatie-actor.
|
|---|
| 22 | if (getTenancy() === 'hub') return res.status(404).type('text/plain').send('Niet beschikbaar in hub-modus');
|
|---|
| 23 | const body = JSON.stringify(buildActor(baseUrl(req)), null, 2);
|
|---|
| 24 | res.type('application/activity+json; charset=utf-8');
|
|---|
| 25 | res.set('Cache-Control', 'public, max-age=300');
|
|---|
| 26 | res.send(body);
|
|---|
| 27 | });
|
|---|
| 28 |
|
|---|
| 29 | router.get('/.klonkt/outbox.json', (req, res) => {
|
|---|
| 30 | if (getTenancy() === 'hub') return res.status(404).type('text/plain').send('Niet beschikbaar in hub-modus');
|
|---|
| 31 | const body = JSON.stringify(buildOutbox(baseUrl(req)), null, 2);
|
|---|
| 32 | res.type('application/activity+json; charset=utf-8');
|
|---|
| 33 | res.set('Cache-Control', 'public, max-age=300');
|
|---|
| 34 | res.set('Klonkt-Signature', `ed25519=${signBody(body)}`);
|
|---|
| 35 | res.send(body);
|
|---|
| 36 | });
|
|---|
| 37 |
|
|---|
| 38 | export default router;
|
|---|