source: Klonkt/src/routes/federation.js@ 4c9c60b

main
Last change on this file since 4c9c60b was 834bcc3, checked in by Robin Genis <roboburr@…>, 3 months ago

i18n: translate Dutch code comments to English across src/

Comments in routes/services/views/config/middleware/assets translated to
English for the public repo. A few dev-facing throw/console message strings
were Englished too. No user-facing UI strings or i18n dictionary values changed
(src/services/i18n.js untouched). Logic unchanged.

Co-Authored-By: Claude <noreply@…>

  • Property mode set to 100644
File size: 2.4 KB
Line 
1// routes/federation.js — public Cirkels endpoints (v1, publication side).
2//
3// GET /.klonkt/actor.json — ActivityStreams actor + Ed25519 public key
4// GET /.klonkt/outbox.json — public posts as AS Create objects,
5// signed via the Klonkt-Signature header
6//
7// Site-agnostic and unauthenticated — read-only. See docs/cirkels-v1-spec.md.
8
9import express from 'express';
10import { buildActor, buildOutbox, signBody, KLONKT_PROTO, MIN_PROTO } from '../services/CircleFederation.js';
11import { getTenancy } from '../services/SettingsService.js';
12
13const router = express.Router();
14
15function baseUrl(req) {
16 const b = process.env.PUBLIC_BASE_URL || `${req.protocol}://${req.get('host')}`;
17 return b.replace(/\/+$/, '');
18}
19
20// The proto the consumer claims to be running (from their request header), or 0.
21function consumerProto(req) {
22 return parseInt(req.get('Klonkt-Proto') || '0', 10) || 0;
23}
24
25router.get('/.klonkt/actor.json', (req, res) => {
26 // Circles = solo-to-solo; hubs do not publish a federation actor.
27 if (getTenancy() === 'hub') return res.status(404).type('text/plain').send('Niet beschikbaar in hub-modus');
28 // We ALWAYS serve the actor (including to older consumers) so they can read our
29 // proto and show a clean "update required" message.
30 const body = JSON.stringify(buildActor(baseUrl(req)), null, 2);
31 res.type('application/activity+json; charset=utf-8');
32 res.set('Klonkt-Proto', String(KLONKT_PROTO));
33 res.set('Cache-Control', 'public, max-age=300');
34 res.send(body);
35});
36
37router.get('/.klonkt/outbox.json', (req, res) => {
38 if (getTenancy() === 'hub') return res.status(404).type('text/plain').send('Niet beschikbaar in hub-modus');
39 res.set('Klonkt-Proto', String(KLONKT_PROTO));
40 // Consumer too old? Reject with 426 Upgrade Required (the crypto binding already
41 // excludes them; this gives an explicit, readable signal). proto 0 = no header
42 // (e.g. a browser/curl) → allow, they won't verify anyway.
43 const cp = consumerProto(req);
44 if (cp && cp < MIN_PROTO) {
45 return res.status(426).type('text/plain')
46 .send(`Upgrade Required: deze cirkel draait proto ${KLONKT_PROTO}; jouw Klonkt (proto ${cp}) is te oud.`);
47 }
48 const body = JSON.stringify(buildOutbox(baseUrl(req)), null, 2);
49 res.type('application/activity+json; charset=utf-8');
50 res.set('Cache-Control', 'public, max-age=300');
51 res.set('Klonkt-Signature', `ed25519=${signBody(body)}`);
52 res.send(body);
53});
54
55export default router;
Note: See TracBrowser for help on using the repository browser.