javascript-solid-server 0.0.186 → 0.0.188

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "javascript-solid-server",
3
- "version": "0.0.186",
3
+ "version": "0.0.188",
4
4
  "description": "A minimal, fast Solid server",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
package/src/server.js CHANGED
@@ -28,6 +28,7 @@ import { webrtcPlugin } from './webrtc/index.js';
28
28
  import { tunnelPlugin } from './tunnel/index.js';
29
29
  import { terminalPlugin } from './terminal/index.js';
30
30
  import { registerErrorHandler } from './utils/error-handler.js';
31
+ import { seedServerRoot } from './ui/server-root.js';
31
32
 
32
33
  const __dirname = dirname(fileURLToPath(import.meta.url));
33
34
 
@@ -762,6 +763,48 @@ export function createServer(options = {}) {
762
763
  fastify.options('/', handleOptions);
763
764
  fastify.post('/', writeRateLimit, handlePost);
764
765
 
766
+ // Server-root landing page: seed /index.html and a public-read /.acl
767
+ // on first start (skip-if-exists, so operator-provided files are
768
+ // preserved). See #433 / #276. Skipped in read-only deployments so
769
+ // startup never mutates DATA_ROOT.
770
+ if (!options.readOnly) {
771
+ fastify.addHook('onReady', async () => {
772
+ // A missing or unreadable package.json (some production bundles
773
+ // omit it) shouldn't block seeding; fall back to "unknown".
774
+ let version = 'unknown';
775
+ try {
776
+ const pkg = await readFile(join(__dirname, '..', 'package.json'), 'utf8');
777
+ ({ version } = JSON.parse(pkg));
778
+ } catch (err) {
779
+ fastify.log.warn({ err }, 'Failed to read package.json version; seeding server root with version=unknown');
780
+ }
781
+
782
+ try {
783
+ await seedServerRoot({
784
+ version,
785
+ singleUser,
786
+ idp: idpEnabled,
787
+ singleUserName,
788
+ enabled: {
789
+ idp: idpEnabled,
790
+ nostr: nostrEnabled,
791
+ webrtc: webrtcEnabled,
792
+ activitypub: activitypubEnabled,
793
+ git: gitEnabled,
794
+ pay: payEnabled,
795
+ notifications: notificationsEnabled,
796
+ mashlib: mashlibEnabled,
797
+ mongo: mongoEnabled,
798
+ tunnel: tunnelEnabled,
799
+ terminal: terminalEnabled
800
+ }
801
+ });
802
+ } catch (err) {
803
+ fastify.log.warn({ err }, 'Failed to seed server root');
804
+ }
805
+ });
806
+ }
807
+
765
808
  // Single-user mode: create pod on startup if it doesn't exist
766
809
  if (singleUser) {
767
810
  fastify.addHook('onReady', async () => {
@@ -0,0 +1,131 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>JSS Solid pod</title>
7
+ <meta name="description" content="A Solid pod server powered by JSS">
8
+ <style>
9
+ * { margin: 0; padding: 0; box-sizing: border-box; }
10
+ body {
11
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
12
+ background: #fafaf8;
13
+ color: #2c2c2c;
14
+ line-height: 1.6;
15
+ min-height: 100vh;
16
+ display: flex;
17
+ align-items: center;
18
+ justify-content: center;
19
+ padding: 2rem;
20
+ }
21
+ .container { max-width: 600px; width: 100%; }
22
+ h1 { font-size: 2.2rem; font-weight: 500; margin-bottom: 1rem; }
23
+ .lede { font-size: 1.05rem; margin-bottom: 1rem; color: #2c2c2c; }
24
+ .lede a { color: #2c2c2c; text-decoration: none; border-bottom: 1px dashed #aaa; }
25
+ .lede a:hover { border-bottom-color: #2c2c2c; }
26
+ .explainer { color: #666; font-size: 0.95rem; margin-bottom: 2rem; padding-bottom: 1.5rem; border-bottom: 1px solid #ddd; }
27
+ .actions { display: flex; gap: 0.75rem; margin: 0 0 2rem; flex-wrap: wrap; }
28
+ .btn {
29
+ display: inline-block;
30
+ padding: 0.6rem 1.2rem;
31
+ border-radius: 4px;
32
+ text-decoration: none;
33
+ font-size: 0.95rem;
34
+ border: 1px solid transparent;
35
+ cursor: pointer;
36
+ transition: background 0.1s, border-color 0.1s;
37
+ }
38
+ /* The .btn { display: inline-block } above otherwise overrides the
39
+ browser's UA `[hidden] { display: none }` rule (equal specificity,
40
+ author rule wins because it's later in the cascade). Without this,
41
+ the Sign up / Sign in buttons would flash visible before the HEAD
42
+ probe runs. !important keeps the [hidden] attribute authoritative. */
43
+ [hidden] { display: none !important; }
44
+ .btn-primary { background: #2c2c2c; color: #fff; }
45
+ .btn-primary:hover { background: #000; }
46
+ .btn-secondary { background: #fff; color: #2c2c2c; border-color: #ccc; }
47
+ .btn-secondary:hover { background: #f0efeb; }
48
+ footer { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid #ddd; color: #999; font-size: 0.8rem; text-align: center; }
49
+ footer a { color: #888; }
50
+ footer small { display: block; margin-top: 0.5rem; }
51
+ footer code { font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace; }
52
+ </style>
53
+ </head>
54
+ <body>
55
+ <div class="container">
56
+ <h1>Welcome</h1>
57
+ <!-- The fallback href="./" is page-relative so it stays inside any
58
+ reverse-proxy mount even if the script below doesn't run
59
+ (CSP, JS disabled). The script will replace it with the
60
+ absolute URL of the document base on load. -->
61
+ <p class="lede">Your JSS Solid pod is running at <a id="server-url" href="./">this server</a>.</p>
62
+ <p class="explainer">This is a Solid pod server. Solid is an open standard for personal data — your data lives in pods you own, and apps connect to it.</p>
63
+
64
+ <div class="actions">
65
+ <a href="https://jss.live/docs/getting-started/introduction" class="btn btn-primary">Get started →</a>
66
+ <!-- IdP links are written page-relative (no leading slash) so they
67
+ resolve against document base, surviving reverse-proxy mounts
68
+ at a path prefix (e.g. https://example/jss/). Origin-root
69
+ absolute paths like /idp would jump out of the mount point.
70
+ Same rationale as the relative ACL targets from #428. -->
71
+ <a href="./idp/register" class="btn btn-secondary" data-cond="register" hidden>Sign up</a>
72
+ <a href="./idp" class="btn btn-secondary" data-cond="login" hidden>Sign in</a>
73
+ </div>
74
+
75
+ <!-- Version, mode, and enabled-feature pills used to live here.
76
+ All three would go stale on the next mode change or upgrade
77
+ because the seed is skip-if-exists. The CLI banner already
78
+ lists them at startup. Surface them via a runtime probe in
79
+ a follow-up if needed. See #435. -->
80
+
81
+
82
+ <footer>
83
+ Powered by <a href="https://jss.live">JSS</a> · <a href="https://github.com/JavaScriptSolidServer/JavaScriptSolidServer">GitHub</a>
84
+ <small>Customise this page: edit <code>/index.html</code> in your data dir</small>
85
+ </footer>
86
+ </div>
87
+
88
+ <script>
89
+ // Render the live server URL the visitor actually used. Adapts to
90
+ // whichever hostname/port they hit (localhost / 127.0.0.1 / LAN-IP
91
+ // / public domain) and — importantly — preserves any reverse-proxy
92
+ // path prefix the server is mounted under. `window.location.origin`
93
+ // alone would drop a /jss/ mount and display the proxy origin
94
+ // instead. `new URL('./', window.location.href)` resolves to the
95
+ // current document's directory, which is the JSS server root.
96
+ (function () {
97
+ var el = document.getElementById('server-url');
98
+ if (!el) return;
99
+ var base = new URL('./', window.location.href).href;
100
+ el.textContent = base;
101
+ el.href = base;
102
+ })();
103
+
104
+ // HEAD-adaptive Sign up / Sign in. Reveals each button based on what
105
+ // the IDP currently exposes — the same seeded HTML works for
106
+ // single-user, multi-user-with-IDP, and no-IDP modes without
107
+ // regeneration on mode change.
108
+ // 200 → registration open: show both Sign up and Sign in
109
+ // 403 → IDP enabled but registration disabled (single-user mode):
110
+ // Sign in only
111
+ // 404 / network error → no IDP: hide both
112
+ (function () {
113
+ // Relative URL resolves against document base, same as the
114
+ // anchor hrefs above — preserves the path-prefix mount point.
115
+ fetch('./idp/register', { method: 'HEAD', cache: 'no-store' })
116
+ .then(function (res) {
117
+ var register = document.querySelector('[data-cond="register"]');
118
+ var login = document.querySelector('[data-cond="login"]');
119
+ if (res.status === 200) {
120
+ if (register) register.hidden = false;
121
+ if (login) login.hidden = false;
122
+ } else if (res.status === 403) {
123
+ if (login) login.hidden = false;
124
+ }
125
+ // 404 / other / network error: leave both hidden
126
+ })
127
+ .catch(function () { /* network error: leave both hidden */ });
128
+ })();
129
+ </script>
130
+ </body>
131
+ </html>
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Server-root landing page.
3
+ *
4
+ * Renders src/ui/server-root.html with runtime values, and seeds
5
+ * DATA_ROOT/index.html + DATA_ROOT/.acl on first start (skip-if-exists,
6
+ * so operator customisation is preserved).
7
+ *
8
+ * See issue #276.
9
+ */
10
+
11
+ import { readFileSync } from 'fs';
12
+ import { fileURLToPath } from 'url';
13
+ import { dirname, join } from 'path';
14
+ import * as storage from '../storage/filesystem.js';
15
+ import { generatePublicReadAcl, serializeAcl } from '../wac/parser.js';
16
+
17
+ const __dirname = dirname(fileURLToPath(import.meta.url));
18
+ const TEMPLATE_PATH = join(__dirname, 'server-root.html');
19
+
20
+ /**
21
+ * Read the landing page template and return it as an HTML string.
22
+ *
23
+ * The seeded HTML is fully static — no template substitution. Anything
24
+ * we used to render in (mode, enabled features, version) would have
25
+ * gone stale on the next mode change or upgrade because the seed is
26
+ * skip-if-exists. They've been dropped from the template; the CLI
27
+ * banner lists them at startup, and Sign up / Sign in adapt at load
28
+ * time via the inline HEAD probe (see decideRevealForRegisterStatus
29
+ * below for the matrix that the inline script implements).
30
+ *
31
+ * The function still takes (and ignores) a `_ctx` arg for forward
32
+ * compatibility — callers (seedServerRoot, server.js) pass one.
33
+ *
34
+ * @param {object} [_ctx] - Reserved; currently unused.
35
+ * @returns {string} HTML
36
+ */
37
+ // eslint-disable-next-line no-unused-vars
38
+ export function renderServerRoot(_ctx = {}) {
39
+ return readFileSync(TEMPLATE_PATH, 'utf8');
40
+ }
41
+
42
+ /**
43
+ * Decide which conditional buttons (Sign up, Sign in) to reveal based
44
+ * on the response status of `HEAD /idp/register`. Pure function so the
45
+ * 200 / 403 / 404 matrix can be unit-tested without DOM. The inline
46
+ * script in server-root.html implements the same matrix literally;
47
+ * keep them in sync.
48
+ *
49
+ * 200 → registration open: reveal both Sign up and Sign in
50
+ * 403 → IDP enabled but registration disabled (single-user mode):
51
+ * reveal Sign in only
52
+ * anything else (404, network error) → reveal neither (no IDP)
53
+ *
54
+ * @param {number|undefined} status - HTTP status code, or undefined for
55
+ * network error.
56
+ * @returns {{ register: boolean, login: boolean }}
57
+ */
58
+ export function decideRevealForRegisterStatus(status) {
59
+ if (status === 200) return { register: true, login: true };
60
+ if (status === 403) return { register: false, login: true };
61
+ return { register: false, login: false };
62
+ }
63
+
64
+ /**
65
+ * Seed DATA_ROOT/index.html, DATA_ROOT/.acl and DATA_ROOT/index.html.acl
66
+ * if they don't already exist. Operator's own files are never overwritten.
67
+ *
68
+ * Default ACL: public read. No write access — the operator edits
69
+ * /index.html on disk, not via the web.
70
+ *
71
+ * If the HTML write fails (permissions, full disk, read-only DATA_ROOT),
72
+ * ACL seeding is aborted to avoid leaving the server with a public-read
73
+ * root ACL and no index page.
74
+ *
75
+ * @param {object} ctx - Same context passed to renderServerRoot
76
+ * @returns {Promise<{seededHtml: boolean, seededAcl: boolean, seededPageAcl: boolean}>}
77
+ */
78
+ export async function seedServerRoot(ctx = {}) {
79
+ let seededHtml = false;
80
+ let seededAcl = false;
81
+ let seededPageAcl = false;
82
+
83
+ // Seed /index.html if operator hasn't written one.
84
+ if (!(await storage.exists('/index.html'))) {
85
+ const html = renderServerRoot(ctx);
86
+ const ok = await storage.write('/index.html', html);
87
+ if (!ok) {
88
+ // Don't proceed with ACLs if the page itself failed to write —
89
+ // leaves us in a consistent unchanged state.
90
+ return { seededHtml: false, seededAcl: false, seededPageAcl: false };
91
+ }
92
+ seededHtml = true;
93
+ }
94
+
95
+ // Seed /.acl if one doesn't already exist. Public read on the container
96
+ // itself — so GET / serves the landing page. Independent of index.html.
97
+ //
98
+ // Use './' (relative to the .acl's own URL) rather than '/' (the
99
+ // origin root). The two coincide when JSS is mounted at the origin
100
+ // root, but only the relative form survives reverse-proxy mounts at
101
+ // a path prefix (e.g. https://example/jss/). This matches the
102
+ // pattern used by createPodStructure / createRootPodStructure since
103
+ // #428 / #430.
104
+ //
105
+ // (createRootPodStructure in single-user mode writes its own ACL and
106
+ // runs in a later hook, which will overwrite this if needed.)
107
+ if (!(await storage.exists('/.acl'))) {
108
+ const ok = await storage.write('/.acl', serializeAcl(generatePublicReadAcl('./')));
109
+ if (ok) seededAcl = true;
110
+ }
111
+
112
+ // Dedicated ACL for the landing page itself — public read. The container
113
+ // ACL above has no acl:default (we don't want to implicitly publish all
114
+ // children), so /index.html needs its own rule when fetched directly.
115
+ // Same relative-form rationale as above.
116
+ if (!(await storage.exists('/index.html.acl'))) {
117
+ const ok = await storage.write('/index.html.acl', serializeAcl(generatePublicReadAcl('./index.html')));
118
+ if (ok) seededPageAcl = true;
119
+ }
120
+
121
+ return { seededHtml, seededAcl, seededPageAcl };
122
+ }
@@ -0,0 +1,249 @@
1
+ /**
2
+ * Server-root landing page seed (#276 / #433 / #435).
3
+ *
4
+ * Phase 3 (#433) seeded a mode-specific landing page that went stale on
5
+ * mode change. Phase 3 refinement (#435) replaced the mode-specific copy
6
+ * with a single mode-agnostic page that adapts at load time via a HEAD
7
+ * probe against /idp/register, so the same seeded HTML keeps working
8
+ * across modes without regenerating the file.
9
+ */
10
+
11
+ import { describe, it, before, after } from 'node:test';
12
+ import assert from 'node:assert';
13
+ import fs from 'fs-extra';
14
+ import { createServer } from '../src/server.js';
15
+ import { renderServerRoot, decideRevealForRegisterStatus } from '../src/ui/server-root.js';
16
+ import { startTestServer, stopTestServer, request, assertStatus } from './helpers.js';
17
+
18
+ describe('Server-root landing page', () => {
19
+ before(async () => {
20
+ await startTestServer();
21
+ });
22
+
23
+ after(async () => {
24
+ await stopTestServer();
25
+ });
26
+
27
+ it('seeds /index.html so GET / serves HTML', async () => {
28
+ const res = await request('/', { headers: { Accept: 'text/html' } });
29
+ assertStatus(res, 200);
30
+ const body = await res.text();
31
+ assert.match(body, /<title>JSS Solid pod<\/title>/);
32
+ assert.match(body, /Your JSS Solid pod is running/);
33
+ });
34
+
35
+ it('landing page is publicly readable (no auth required)', async () => {
36
+ const res = await request('/index.html');
37
+ assertStatus(res, 200);
38
+ });
39
+
40
+ // Portability regression: the seeded ACLs must use './' (resolved
41
+ // against the .acl's own URL) rather than '/' (the origin root).
42
+ // The two coincide when JSS sits at the origin root, so a request
43
+ // smoke-test would pass either way; only direct inspection of the
44
+ // serialized accessTo catches a regression to the absolute form.
45
+ // Without this, JSS mounted under a reverse-proxy path prefix would
46
+ // see the seeded ACL match the origin root rather than the prefix.
47
+ it('seeded ACLs use relative resourceUrl ("./" / "./index.html"), not absolute paths', async () => {
48
+ const rootAcl = JSON.parse(await fs.readFile('./data/.acl', 'utf8'));
49
+ const pageAcl = JSON.parse(await fs.readFile('./data/index.html.acl', 'utf8'));
50
+ const rootAccessTo = rootAcl['@graph'][0]['acl:accessTo']['@id'];
51
+ const pageAccessTo = pageAcl['@graph'][0]['acl:accessTo']['@id'];
52
+ assert.strictEqual(rootAccessTo, './',
53
+ `Expected /.acl accessTo to be relative './', got '${rootAccessTo}'`);
54
+ assert.strictEqual(pageAccessTo, './index.html',
55
+ `Expected /index.html.acl accessTo to be relative './index.html', got '${pageAccessTo}'`);
56
+ });
57
+ });
58
+
59
+ // Operator's existing /index.html is preserved — dedicated server + data dir.
60
+ describe('Server-root landing — operator override', () => {
61
+ let server;
62
+ let baseUrl;
63
+ let savedDataRoot;
64
+ const DATA_DIR = './test-data-server-root-override';
65
+ const CUSTOM_HTML = '<!doctype html><html><body>my custom page</body></html>';
66
+
67
+ before(async () => {
68
+ // Capture process.env.DATA_ROOT — createServer mutates it when options.root
69
+ // is provided. Restore in after() to avoid cross-test interference with
70
+ // suites that rely on the default ./data dir.
71
+ savedDataRoot = process.env.DATA_ROOT;
72
+
73
+ await fs.remove(DATA_DIR);
74
+ await fs.ensureDir(DATA_DIR);
75
+ await fs.writeFile(`${DATA_DIR}/index.html`, CUSTOM_HTML);
76
+
77
+ server = createServer({
78
+ logger: false,
79
+ root: DATA_DIR,
80
+ forceCloseConnections: true,
81
+ });
82
+ await server.listen({ port: 0, host: '127.0.0.1' });
83
+ baseUrl = `http://127.0.0.1:${server.server.address().port}`;
84
+ });
85
+
86
+ after(async () => {
87
+ await server.close();
88
+ await fs.remove(DATA_DIR);
89
+ if (savedDataRoot === undefined) delete process.env.DATA_ROOT;
90
+ else process.env.DATA_ROOT = savedDataRoot;
91
+ });
92
+
93
+ it('does not overwrite operator-provided /index.html', async () => {
94
+ const current = await fs.readFile(`${DATA_DIR}/index.html`, 'utf8');
95
+ assert.strictEqual(current, CUSTOM_HTML);
96
+ });
97
+
98
+ it('GET / serves operator custom page', async () => {
99
+ const res = await fetch(`${baseUrl}/`, { headers: { Accept: 'text/html' } });
100
+ assert.strictEqual(res.status, 200);
101
+ const body = await res.text();
102
+ assert.match(body, /my custom page/);
103
+ });
104
+ });
105
+
106
+ describe('renderServerRoot', () => {
107
+ // The seeded HTML is fully static — no template substitution, no
108
+ // values vary by request. This is deliberate: anything dynamic
109
+ // (mode, features, version) goes stale on the next mode change or
110
+ // upgrade because the seed is skip-if-exists. Static = honest.
111
+ it('renders byte-identical HTML regardless of the ctx passed', () => {
112
+ const a = renderServerRoot({ version: '1.0.0', singleUser: true, enabled: { idp: true } });
113
+ const b = renderServerRoot({ version: '99.0.0', singleUser: false, enabled: {} });
114
+ const c = renderServerRoot();
115
+ assert.strictEqual(a, b);
116
+ assert.strictEqual(b, c);
117
+ assert.match(a, /<h1>Welcome<\/h1>/);
118
+ assert.match(a, /Your JSS Solid pod is running/);
119
+ assert.match(a, /open standard for personal data/);
120
+ });
121
+
122
+ it('does not bake mode, feature, or version pills into the seeded HTML', () => {
123
+ // All three would go stale across mode changes / upgrades because
124
+ // the seed is skip-if-exists. The CLI banner already lists them
125
+ // at startup. Excluded from the seed entirely.
126
+ const html = renderServerRoot({ version: '1.2.3', singleUser: true, enabled: { idp: true, nostr: true } });
127
+ assert.doesNotMatch(html, /<code>single-user<\/code>/);
128
+ assert.doesNotMatch(html, /<span>idp<\/span>/);
129
+ assert.doesNotMatch(html, /<span>nostr<\/span>/);
130
+ assert.doesNotMatch(html, /<code>1\.2\.3<\/code>/);
131
+ // No info box at all — there's nothing left to put in it.
132
+ assert.doesNotMatch(html, /class="info"/);
133
+ });
134
+
135
+ it('always emits the Get started button pointing at the docs introduction', () => {
136
+ const html = renderServerRoot({ version: '1.0.0' });
137
+ // The canonical URL is the introduction page, not the category.
138
+ // Docusaurus 3 doesn't auto-generate a category index page, so
139
+ // /docs/getting-started/ would 404. Link to the real document.
140
+ assert.match(html, /href="https:\/\/jss\.live\/docs\/getting-started\/introduction"/);
141
+ assert.match(html, /Get started/);
142
+ });
143
+
144
+ it('emits Sign up + Sign in buttons hidden for the HEAD probe to reveal, with page-relative hrefs', () => {
145
+ const html = renderServerRoot({ version: '1.0.0' });
146
+ // Page-relative (./idp/...) so a reverse-proxy mount under a path
147
+ // prefix sends visitors into the correct prefix instead of the
148
+ // origin root. Same rationale as the ./ ACL targets from #428.
149
+ assert.match(html, /<a href="\.\/idp\/register"[^>]*data-cond="register"[^>]*hidden/);
150
+ assert.match(html, /<a href="\.\/idp"[^>]*data-cond="login"[^>]*hidden/);
151
+ assert.doesNotMatch(html, /<a href="\/idp\/register"/,
152
+ 'Sign up href must be page-relative for path-prefix portability');
153
+ assert.doesNotMatch(html, /<a href="\/idp"/,
154
+ 'Sign in href must be page-relative for path-prefix portability');
155
+ assert.match(html, /Sign up/);
156
+ assert.match(html, /Sign in/);
157
+ });
158
+
159
+ it('overrides the .btn display rule for the [hidden] attribute so the buttons actually start hidden', () => {
160
+ // Without an explicit !important [hidden] rule, the .btn class's
161
+ // display:inline-block beats the UA stylesheet's [hidden]{display:none}
162
+ // and the Sign up / Sign in anchors flash visible before the HEAD probe
163
+ // finishes. The CSS rule is the load-bearing piece; assert it's there.
164
+ const html = renderServerRoot({ version: '1.0.0' });
165
+ assert.match(html, /\[hidden\]\s*\{[^}]*display:\s*none\s*!important/);
166
+ });
167
+
168
+ it('includes the HEAD-adaptive script targeting ./idp/register (page-relative)', () => {
169
+ const html = renderServerRoot({ version: '1.0.0' });
170
+ // Same path-prefix portability concern as the anchor hrefs.
171
+ assert.match(html, /fetch\(['"]\.\/idp\/register['"]/);
172
+ assert.doesNotMatch(html, /fetch\(['"]\/idp\/register['"]/,
173
+ 'HEAD probe URL must be page-relative for path-prefix portability');
174
+ assert.match(html, /method:\s*['"]HEAD['"]/);
175
+ assert.match(html, /res\.status === 200/);
176
+ assert.match(html, /res\.status === 403/);
177
+ });
178
+
179
+ it('includes the live-URL script that resolves the document base, not just origin', () => {
180
+ const html = renderServerRoot({ version: '1.0.0' });
181
+ assert.match(html, /id="server-url"/);
182
+ // Must use new URL('./', window.location.href) so a reverse-proxy
183
+ // mount at a path prefix is preserved. window.location.origin alone
184
+ // would drop the prefix and display the proxy origin instead.
185
+ assert.match(html, /new URL\(['"]\.\/['"],\s*window\.location\.href\)/);
186
+ assert.doesNotMatch(html, /textContent\s*=\s*window\.location\.origin/,
187
+ 'live-URL must not display origin-only — it would drop the path prefix on reverse-proxy mounts');
188
+ });
189
+
190
+ it('uses a page-relative fallback href on the live-URL anchor', () => {
191
+ // Before the script runs (or if scripts are blocked / blocked by CSP),
192
+ // the anchor is still clickable. A href="/" fallback would escape
193
+ // any reverse-proxy path prefix; use href="./" so the link stays
194
+ // inside the mount.
195
+ const html = renderServerRoot({ version: '1.0.0' });
196
+ assert.match(html, /<a id="server-url" href="\.\/"/);
197
+ assert.doesNotMatch(html, /<a id="server-url" href="\/"/,
198
+ 'fallback href must be page-relative for path-prefix portability');
199
+ });
200
+
201
+ it('points the footer at the GitHub repo and the customise hint', () => {
202
+ const html = renderServerRoot({ version: '1.0.0' });
203
+ assert.match(html, /href="https:\/\/github\.com\/JavaScriptSolidServer\/JavaScriptSolidServer"/);
204
+ assert.match(html, /Customise this page/);
205
+ assert.match(html, /<code>\/index\.html<\/code>/);
206
+ });
207
+ });
208
+
209
+ // Pure-function unit tests for the HEAD response → button-reveal matrix.
210
+ // The inline script in server-root.html implements the same matrix by
211
+ // hand; a regex check on the script text (above) catches outright drops
212
+ // of the literals, but only this helper test pins down the *behaviour*
213
+ // of the matrix without needing a DOM.
214
+ describe('decideRevealForRegisterStatus', () => {
215
+ it('reveals both Sign up and Sign in for HTTP 200 (registration open)', () => {
216
+ assert.deepStrictEqual(
217
+ decideRevealForRegisterStatus(200),
218
+ { register: true, login: true }
219
+ );
220
+ });
221
+
222
+ it('reveals only Sign in for HTTP 403 (single-user — registration disabled)', () => {
223
+ assert.deepStrictEqual(
224
+ decideRevealForRegisterStatus(403),
225
+ { register: false, login: true }
226
+ );
227
+ });
228
+
229
+ it('reveals neither for HTTP 404 (no IDP)', () => {
230
+ assert.deepStrictEqual(
231
+ decideRevealForRegisterStatus(404),
232
+ { register: false, login: false }
233
+ );
234
+ });
235
+
236
+ it('reveals neither for any other status (e.g. 500)', () => {
237
+ assert.deepStrictEqual(
238
+ decideRevealForRegisterStatus(500),
239
+ { register: false, login: false }
240
+ );
241
+ });
242
+
243
+ it('reveals neither when status is undefined (network error)', () => {
244
+ assert.deepStrictEqual(
245
+ decideRevealForRegisterStatus(undefined),
246
+ { register: false, login: false }
247
+ );
248
+ });
249
+ });