2 Commits

Author SHA1 Message Date
mnovak bd95a1d2c7 Merge pull request '[relay] Attribution: GET /about serves the CPAL credit and the source URL' (#2) from fix/relay-attribution into main
Merge #2: [relay] Attribution: GET /about serves the CPAL credit and the source URL
2026-11-24 07:39:34 +01:00
Marek Novák 3256adece3 [relay] Attribution: GET /about serves the CPAL credit and the source URL (Ludus G9.130) 2026-11-24 07:37:11 +01:00
7 changed files with 109 additions and 7 deletions
+4
View File
@@ -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 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*. 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). The dependencies keep their own licences (`@noble/curves` and `better-sqlite3`: MIT).
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "ludus-public", "name": "ludus-public",
"version": "0.1.0", "version": "0.1.1",
"private": true, "private": true,
"license": "CPAL-1.0", "license": "CPAL-1.0",
"type": "module", "type": "module",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@ludus/relay", "name": "@ludus/relay",
"version": "0.1.0", "version": "0.1.1",
"private": true, "private": true,
"license": "CPAL-1.0", "license": "CPAL-1.0",
"type": "module", "type": "module",
+23 -1
View File
@@ -39,7 +39,29 @@ function intFromEnv(name: string, fallback: number): number {
const host = process.env['LUDUS_RELAY_HOST'] ?? '127.0.0.1'; const host = process.env['LUDUS_RELAY_HOST'] ?? '127.0.0.1';
const port = intFromEnv('LUDUS_RELAY_PORT', 8787); const port = intFromEnv('LUDUS_RELAY_PORT', 8787);
const dbPath = process.env['LUDUS_RELAY_DB'] ?? './ludus-relay.db'; 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 store = RelayStore.open(dbPath);
const running = await startRelay({ store, config, host, port }); const running = await startRelay({ store, config, host, port });
+26 -1
View File
@@ -58,6 +58,17 @@ export interface RelayConfig {
* not silently truncated at a number they never chose. * not silently truncated at a number they never chose.
*/ */
readonly boardMaxRows: number; 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 = { export const DEFAULT_RELAY_CONFIG: RelayConfig = {
@@ -65,9 +76,23 @@ export const DEFAULT_RELAY_CONFIG: RelayConfig = {
displayNameMaxChars: 32, displayNameMaxChars: 32,
leagueIdMaxChars: 64, leagueIdMaxChars: 64,
maxBodyBytes: 8 * 1024, 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> = {}): RelayConfig { export function relayConfig(overrides: Partial<RelayConfig> = {}): RelayConfig {
return { ...DEFAULT_RELAY_CONFIG, ...overrides }; return { ...DEFAULT_RELAY_CONFIG, ...overrides };
} }
+21 -3
View File
@@ -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. * 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 { createServer, type IncomingMessage, type Server, type ServerResponse } from 'node:http';
import { ludusError, type LudusError } from '@ludus/schema'; 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 { RelayStore } from './store.js';
import { checkSubmission } from './verify.js'; import { checkSubmission } from './verify.js';
import { currentWeekId } from './week.js'; import { currentWeekId } from './week.js';
@@ -170,6 +170,24 @@ export function relayHandler(options: RelayServerOptions) {
return; 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/')) { if (req.method === 'GET' && url.pathname.startsWith('/league/')) {
const leagueId = decodeURIComponent(url.pathname.slice('/league/'.length)); const leagueId = decodeURIComponent(url.pathname.slice('/league/'.length));
if (leagueId === '' || leagueId.length > config.leagueIdMaxChars) { if (leagueId === '' || leagueId.length > config.leagueIdMaxChars) {
@@ -239,7 +257,7 @@ export function relayHandler(options: RelayServerOptions) {
404, 404,
ludusError( ludusError(
'relay/no-such-route', 'relay/no-such-route',
'This relay serves GET /health, GET /league/<id> and POST /submit.' 'This relay serves GET /about, GET /health, GET /league/<id> and POST /submit.'
) )
); );
} catch (cause) { } catch (cause) {
+33
View File
@@ -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', () => { describe('POST /submit', () => {
it('accepts a signed submission and reports what was stored', async () => { it('accepts a signed submission and reports what was stored', async () => {
const { status, json } = await post('/submit', signedSubmission(keyFor(1))); const { status, json } = await post('/submit', signedSubmission(keyFor(1)));