diff --git a/README.md b/README.md index 55f241c..41a208b 100644 --- a/README.md +++ b/README.md @@ -45,4 +45,8 @@ if a copy here differs from the code Ludus ships. This repository started from L or runs it as a service for others, must show the Exhibit B credit: **Built on Domi**, linking to https://aula.marek-novak.cz, with the notice *Copyright (c) 2026 Marek Novák*. +A running relay shows that credit itself: `GET /about` (and `GET /`) answers with the credit, the copyright and +the URL of its source. If you run a **modified** relay, set `LUDUS_RELAY_SOURCE_URL` to where your changed code +can be read. §15 makes running it for others a distribution, and the source owed is the code that runs. + The dependencies keep their own licences (`@noble/curves` and `better-sqlite3`: MIT). diff --git a/package.json b/package.json index e6162f4..a502113 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ludus-public", - "version": "0.1.0", + "version": "0.1.1", "private": true, "license": "CPAL-1.0", "type": "module", diff --git a/relay/package.json b/relay/package.json index 60b4b56..94495d1 100644 --- a/relay/package.json +++ b/relay/package.json @@ -1,6 +1,6 @@ { "name": "@ludus/relay", - "version": "0.1.0", + "version": "0.1.1", "private": true, "license": "CPAL-1.0", "type": "module", diff --git a/relay/src/bin.ts b/relay/src/bin.ts index 4ac5f43..c3914c7 100644 --- a/relay/src/bin.ts +++ b/relay/src/bin.ts @@ -39,7 +39,29 @@ function intFromEnv(name: string, fallback: number): number { const host = process.env['LUDUS_RELAY_HOST'] ?? '127.0.0.1'; const port = intFromEnv('LUDUS_RELAY_PORT', 8787); const dbPath = process.env['LUDUS_RELAY_DB'] ?? './ludus-relay.db'; -const config = relayConfig({ xpCeiling: intFromEnv('LUDUS_RELAY_XP_CEILING', 5000) }); +/** An http(s) URL, or exit: a source link nobody can open does not make the source available. */ +function urlFromEnv(name: string): string | undefined { + const raw = process.env[name]; + if (raw === undefined || raw.trim() === '') return undefined; + let parsed: URL | undefined; + try { + parsed = new URL(raw.trim()); + } catch { + parsed = undefined; // reported just below, with the value, and the process exits + } + if (parsed === undefined || (parsed.protocol !== 'https:' && parsed.protocol !== 'http:')) { + console.error(`[relay] ${name} must be an http(s) URL; got ${JSON.stringify(raw)}.`); + process.exit(1); + } + return parsed.href; +} + +// A self-hoster running a modified relay points this at their own source (CPAL-1.0 §15; see `config.ts`). +const sourceUrl = urlFromEnv('LUDUS_RELAY_SOURCE_URL'); +const config = relayConfig({ + xpCeiling: intFromEnv('LUDUS_RELAY_XP_CEILING', 5000), + ...(sourceUrl ? { sourceUrl } : {}) +}); const store = RelayStore.open(dbPath); const running = await startRelay({ store, config, host, port }); diff --git a/relay/src/config.ts b/relay/src/config.ts index 7029bed..2366937 100644 --- a/relay/src/config.ts +++ b/relay/src/config.ts @@ -58,6 +58,17 @@ export interface RelayConfig { * not silently truncated at a number they never chose. */ readonly boardMaxRows: number; + + /** + * Where the source of THIS running relay can be read, served by `GET /about`. + * + * The relay is published under CPAL-1.0 as LudusPublic, and CPAL §15 counts running it for other people as + * distributing it: whoever runs it must make its source available to the people who use it. A relay is an + * API with no screen, so the place its users can find that source is a response. The default is LudusPublic + * itself; a self-hoster running a MODIFIED relay must point this at their own copy, because the obligation is + * to publish the code that runs, not the code it was forked from. + */ + readonly sourceUrl: string; } export const DEFAULT_RELAY_CONFIG: RelayConfig = { @@ -65,9 +76,23 @@ export const DEFAULT_RELAY_CONFIG: RelayConfig = { displayNameMaxChars: 32, leagueIdMaxChars: 64, maxBodyBytes: 8 * 1024, - boardMaxRows: 200 + boardMaxRows: 200, + sourceUrl: 'https://gitea.marek-novak.cz/mnovak/LudusPublic' }; +/** + * The CPAL-1.0 Exhibit B credit, exactly as LudusPublic's LICENSE states it. + * + * Not configurable: the attribution belongs to the Original Developer and a relay may not drop it (CPAL §14). + * Copied from the licence rather than paraphrased; `server.test.ts` checks the words. + */ +export const ATTRIBUTION = { + phrase: 'Built on Domi', + url: 'https://aula.marek-novak.cz', + copyright: 'Copyright (c) 2026 Marek Novák', + licence: 'CPAL-1.0' +} as const; + export function relayConfig(overrides: Partial = {}): RelayConfig { return { ...DEFAULT_RELAY_CONFIG, ...overrides }; } diff --git a/relay/src/server.ts b/relay/src/server.ts index cc88a7f..34edca3 100644 --- a/relay/src/server.ts +++ b/relay/src/server.ts @@ -1,5 +1,5 @@ /** - * The HTTP surface. Three routes, and one of them writes. + * The HTTP surface. Four routes, and one of them writes. * * ══════════════════════════════════════════════════════════════════════════ * WHAT THIS PROCESS LOGS: server faults, and nothing else. @@ -29,7 +29,7 @@ */ import { createServer, type IncomingMessage, type Server, type ServerResponse } from 'node:http'; import { ludusError, type LudusError } from '@ludus/schema'; -import { DEFAULT_RELAY_CONFIG, type RelayConfig } from './config.js'; +import { ATTRIBUTION, DEFAULT_RELAY_CONFIG, type RelayConfig } from './config.js'; import { RelayStore } from './store.js'; import { checkSubmission } from './verify.js'; import { currentWeekId } from './week.js'; @@ -170,6 +170,24 @@ export function relayHandler(options: RelayServerOptions) { return; } + if (req.method === 'GET' && (url.pathname === '/about' || url.pathname === '/')) { + // What this code is and where its source is. CPAL-1.0 §15 treats running the relay for other people as + // distributing it, so its users are owed the source and the Exhibit B credit; the README reaches people + // who read the repository, and this reaches the people who use a running relay. Served on `/` too, + // because `/` is what somebody types when they want to know what a URL is. Static: nothing about the + // request, the store or anybody in it. + send(res, 200, { + ok: true, + name: 'LudusPublic league relay', + builtOn: ATTRIBUTION.phrase, + attributionUrl: ATTRIBUTION.url, + copyright: ATTRIBUTION.copyright, + licence: ATTRIBUTION.licence, + source: config.sourceUrl + }); + return; + } + if (req.method === 'GET' && url.pathname.startsWith('/league/')) { const leagueId = decodeURIComponent(url.pathname.slice('/league/'.length)); if (leagueId === '' || leagueId.length > config.leagueIdMaxChars) { @@ -239,7 +257,7 @@ export function relayHandler(options: RelayServerOptions) { 404, ludusError( 'relay/no-such-route', - 'This relay serves GET /health, GET /league/ and POST /submit.' + 'This relay serves GET /about, GET /health, GET /league/ and POST /submit.' ) ); } catch (cause) { diff --git a/relay/test/server.test.ts b/relay/test/server.test.ts index f912a66..7688e14 100644 --- a/relay/test/server.test.ts +++ b/relay/test/server.test.ts @@ -80,6 +80,39 @@ describe('GET /health', () => { }); }); +describe('GET /about', () => { + it('serves the CPAL Exhibit B credit and where the source is, on /about and on /', async () => { + for (const path of ['/about', '/']) { + const res = await fetch(url(path)); + expect(res.status, path).toBe(200); + expect(await res.json(), path).toEqual({ + ok: true, + name: 'LudusPublic league relay', + builtOn: 'Built on Domi', + attributionUrl: 'https://aula.marek-novak.cz', + copyright: 'Copyright (c) 2026 Marek Novák', + licence: 'CPAL-1.0', + source: 'https://gitea.marek-novak.cz/mnovak/LudusPublic' + }); + } + }); + + it('names the source a self-hoster configured, because a modified relay owes its own', async () => { + const own = await startRelay({ + store, + config: relayConfig({ sourceUrl: 'https://example.invalid/my-relay' }), + now: () => clock + }); + try { + const body = await (await fetch(`http://127.0.0.1:${own.port}/about`)).json(); + expect(body.source).toBe('https://example.invalid/my-relay'); + expect(body.builtOn).toBe('Built on Domi'); + } finally { + await own.close(); + } + }); +}); + describe('POST /submit', () => { it('accepts a signed submission and reports what was stored', async () => { const { status, json } = await post('/submit', signedSubmission(keyFor(1)));