javascript-solid-server 0.0.187 → 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.187",
3
+ "version": "0.0.188",
4
4
  "description": "A minimal, fast Solid server",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -3,68 +3,129 @@
3
3
  <head>
4
4
  <meta charset="UTF-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>{{title}}</title>
7
- <meta name="description" content="A personal data server powered by JSS">
6
+ <title>JSS Solid pod</title>
7
+ <meta name="description" content="A Solid pod server powered by JSS">
8
8
  <style>
9
9
  * { margin: 0; padding: 0; box-sizing: border-box; }
10
10
  body {
11
- font-family: Georgia, 'Times New Roman', serif;
11
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
12
12
  background: #fafaf8;
13
13
  color: #2c2c2c;
14
- line-height: 1.7;
14
+ line-height: 1.6;
15
15
  min-height: 100vh;
16
16
  display: flex;
17
17
  align-items: center;
18
18
  justify-content: center;
19
19
  padding: 2rem;
20
20
  }
21
- .container { max-width: 560px; width: 100%; }
22
- h1 { font-size: 2.2rem; font-weight: 400; margin-bottom: 0.25rem; }
23
- .subtitle { color: #666; font-size: 1.05rem; margin-bottom: 2rem; padding-bottom: 1.5rem; border-bottom: 1px solid #ddd; }
24
- p { margin-bottom: 1.25rem; }
25
- .actions { display: flex; gap: 0.75rem; margin: 1.5rem 0 2rem; flex-wrap: wrap; }
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; }
26
28
  .btn {
27
29
  display: inline-block;
28
30
  padding: 0.6rem 1.2rem;
29
31
  border-radius: 4px;
30
32
  text-decoration: none;
31
- font-family: Georgia, serif;
32
33
  font-size: 0.95rem;
33
34
  border: 1px solid transparent;
34
35
  cursor: pointer;
35
- transition: all 0.1s;
36
+ transition: background 0.1s, border-color 0.1s;
36
37
  }
37
- .btn-primary { background: #7c3aed; color: #fff; }
38
- .btn-primary:hover { background: #6025c0; }
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; }
39
46
  .btn-secondary { background: #fff; color: #2c2c2c; border-color: #ccc; }
40
47
  .btn-secondary:hover { background: #f0efeb; }
41
- .info { background: #f5f4f0; border-radius: 4px; padding: 1rem; font-size: 0.85rem; color: #666; margin-top: 1.5rem; }
42
- .info .row { display: flex; justify-content: space-between; padding: 0.2rem 0; }
43
- .info .label { color: #999; }
44
- .info code { font-family: 'SFMono-Regular', Consolas, monospace; font-size: 0.9em; color: #555; }
45
48
  footer { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid #ddd; color: #999; font-size: 0.8rem; text-align: center; }
46
49
  footer a { color: #888; }
47
- .features { font-size: 0.85rem; color: #666; margin-top: 0.5rem; }
48
- .features span { display: inline-block; background: #eee; padding: 0.15rem 0.5rem; border-radius: 3px; margin-right: 0.3rem; margin-bottom: 0.3rem; font-family: 'SFMono-Regular', Consolas, monospace; font-size: 0.8rem; }
50
+ footer small { display: block; margin-top: 0.5rem; }
51
+ footer code { font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace; }
49
52
  </style>
50
53
  </head>
51
54
  <body>
52
55
  <div class="container">
53
- <h1>{{heading}}</h1>
54
- <div class="subtitle">{{subtitle}}</div>
55
- <p>{{description}}</p>
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>
56
63
 
57
- {{actions}}
58
-
59
- <div class="info">
60
- <div class="row"><span class="label">Version</span><code>{{version}}</code></div>
61
- <div class="row"><span class="label">Mode</span><code>{{mode}}</code></div>
62
- <div class="features">{{features}}</div>
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>
63
73
  </div>
64
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
+
65
82
  <footer>
66
- Powered by <a href="https://jss.live">JSS</a>
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>
67
85
  </footer>
68
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>
69
130
  </body>
70
131
  </html>
@@ -18,100 +18,49 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
18
18
  const TEMPLATE_PATH = join(__dirname, 'server-root.html');
19
19
 
20
20
  /**
21
- * Collect the list of enabled features for display on the landing page.
22
- */
23
- function listFeatures(options = {}) {
24
- const f = [];
25
- if (options.idp) f.push('idp');
26
- if (options.nostr) f.push('nostr');
27
- if (options.webrtc) f.push('webrtc');
28
- if (options.activitypub) f.push('activitypub');
29
- if (options.git) f.push('git');
30
- if (options.pay) f.push('payments');
31
- if (options.notifications) f.push('notifications');
32
- if (options.mashlib) f.push('mashlib');
33
- if (options.mongo) f.push('mongo');
34
- if (options.tunnel) f.push('tunnel');
35
- if (options.terminal) f.push('terminal');
36
- return f;
37
- }
38
-
39
- /**
40
- * Build an HTML snippet of action buttons based on server mode.
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
41
36
  */
42
- function renderActions({ singleUser, idp }) {
43
- const buttons = [];
44
- if (!singleUser && idp) {
45
- buttons.push('<a href="/idp/register" class="btn btn-primary">Create a pod</a>');
46
- buttons.push('<a href="/idp" class="btn btn-secondary">Sign in</a>');
47
- } else if (singleUser && idp) {
48
- buttons.push('<a href="/idp" class="btn btn-primary">Sign in</a>');
49
- }
50
- buttons.push('<a href="https://javascriptsolidserver.github.io/docs/" class="btn btn-secondary">Docs</a>');
51
- return `<div class="actions">${buttons.join('\n ')}</div>`;
37
+ // eslint-disable-next-line no-unused-vars
38
+ export function renderServerRoot(_ctx = {}) {
39
+ return readFileSync(TEMPLATE_PATH, 'utf8');
52
40
  }
53
41
 
54
42
  /**
55
- * Render the landing page as an HTML string.
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.
56
48
  *
57
- * @param {object} ctx
58
- * @param {string} ctx.version - JSS version
59
- * @param {boolean} [ctx.singleUser]
60
- * @param {boolean} [ctx.idp]
61
- * @param {string} [ctx.singleUserName]
62
- * @param {object} [ctx.enabled] - Map of feature flags
63
- * @returns {string} HTML
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 }}
64
57
  */
65
- export function renderServerRoot(ctx = {}) {
66
- const { version = 'unknown', singleUser = false, idp = false, singleUserName, enabled = {} } = ctx;
67
-
68
- const tpl = readFileSync(TEMPLATE_PATH, 'utf8');
69
- const mode = singleUser ? 'single-user' : 'multi-user';
70
- const features = listFeatures(enabled)
71
- .map(f => `<span>${f}</span>`)
72
- .join(' ');
73
-
74
- const heading = 'JSS';
75
- const subtitle = singleUser
76
- ? `Personal pod${singleUserName && singleUserName !== '/' ? ` for ${escape(singleUserName)}` : ''}`
77
- : 'A personal data server';
78
- const description = singleUser
79
- ? 'This server hosts a personal data pod. Apps come to the data rather than the other way around.'
80
- : 'This server hosts personal data pods on the web. Each pod is a space you own, with your own identity and access control.';
81
-
82
- // Single-pass token substitution. Sequential .replace() calls would
83
- // re-scan already-substituted values, so a `singleUserName` of e.g.
84
- // `{{actions}}` would land inside `subtitle`, then get expanded by
85
- // the later `.replace(/{{actions}}/g, …)` — letting a pod owner
86
- // inject other template fragments via their name. With a single
87
- // pass over the original template, each {{token}} is matched once
88
- // and replaced with its value; `$` inside any value is also harmless
89
- // because the function form of replace skips substitution patterns.
90
- // See #433 review thread.
91
- const values = {
92
- title: heading,
93
- heading,
94
- subtitle,
95
- description,
96
- actions: renderActions({ singleUser, idp }),
97
- version: escape(version),
98
- mode,
99
- features
100
- };
101
- return tpl.replace(/{{(\w+)}}/g, (match, key) =>
102
- Object.prototype.hasOwnProperty.call(values, key) ? values[key] : match
103
- );
104
- }
105
-
106
- function escape(s = '') {
107
- return String(s)
108
- .replace(/&/g, '&amp;')
109
- .replace(/</g, '&lt;')
110
- .replace(/>/g, '&gt;')
111
- .replace(/"/g, '&quot;');
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 };
112
62
  }
113
63
 
114
-
115
64
  /**
116
65
  * Seed DATA_ROOT/index.html, DATA_ROOT/.acl and DATA_ROOT/index.html.acl
117
66
  * if they don't already exist. Operator's own files are never overwritten.
@@ -1,12 +1,18 @@
1
1
  /**
2
- * Server-root landing page seed (#276).
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.
3
9
  */
4
10
 
5
11
  import { describe, it, before, after } from 'node:test';
6
12
  import assert from 'node:assert';
7
13
  import fs from 'fs-extra';
8
14
  import { createServer } from '../src/server.js';
9
- import { renderServerRoot } from '../src/ui/server-root.js';
15
+ import { renderServerRoot, decideRevealForRegisterStatus } from '../src/ui/server-root.js';
10
16
  import { startTestServer, stopTestServer, request, assertStatus } from './helpers.js';
11
17
 
12
18
  describe('Server-root landing page', () => {
@@ -22,8 +28,8 @@ describe('Server-root landing page', () => {
22
28
  const res = await request('/', { headers: { Accept: 'text/html' } });
23
29
  assertStatus(res, 200);
24
30
  const body = await res.text();
25
- assert.match(body, /<title>JSS<\/title>/);
26
- assert.match(body, /A personal data server/);
31
+ assert.match(body, /<title>JSS Solid pod<\/title>/);
32
+ assert.match(body, /Your JSS Solid pod is running/);
27
33
  });
28
34
 
29
35
  it('landing page is publicly readable (no auth required)', async () => {
@@ -97,96 +103,147 @@ describe('Server-root landing — operator override', () => {
97
103
  });
98
104
  });
99
105
 
100
- describe('renderServerRoot — mode-specific output', () => {
101
- it('multi-user + IDP shows Create a pod + Sign in', () => {
102
- const html = renderServerRoot({ version: '1.0.0', singleUser: false, idp: true });
103
- assert.match(html, /Create a pod/);
104
- assert.match(html, /href="\/idp\/register"/);
105
- assert.match(html, /href="\/idp"/);
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/);
106
156
  assert.match(html, /Sign in/);
107
157
  });
108
158
 
109
- it('single-user + IDP shows Sign in only (no Create a pod)', () => {
110
- const html = renderServerRoot({ version: '1.0.0', singleUser: true, idp: true, singleUserName: 'alice' });
111
- assert.doesNotMatch(html, /Create a pod/);
112
- assert.match(html, /Sign in/);
113
- });
114
-
115
- it('multi-user without IDP shows only the Docs link', () => {
116
- const html = renderServerRoot({ version: '1.0.0', singleUser: false, idp: false });
117
- assert.doesNotMatch(html, /Create a pod/);
118
- assert.doesNotMatch(html, /Sign in/);
119
- assert.match(html, /Docs/);
120
- });
121
-
122
- it('single-user subtitle includes the pod name when provided', () => {
123
- const html = renderServerRoot({ version: '1.0.0', singleUser: true, idp: false, singleUserName: 'alice' });
124
- assert.match(html, /Personal pod for alice/);
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>/);
125
206
  });
207
+ });
126
208
 
127
- it('lists enabled features', () => {
128
- const html = renderServerRoot({
129
- version: '1.0.0',
130
- singleUser: false,
131
- idp: true,
132
- enabled: { idp: true, nostr: true, webrtc: true, terminal: true }
133
- });
134
- assert.match(html, /<span>idp<\/span>/);
135
- assert.match(html, /<span>nostr<\/span>/);
136
- assert.match(html, /<span>webrtc<\/span>/);
137
- assert.match(html, /<span>terminal<\/span>/);
138
- });
139
-
140
- it('interpolates version', () => {
141
- const html = renderServerRoot({ version: '9.9.9' });
142
- assert.match(html, /<code>9\.9\.9<\/code>/);
143
- });
144
-
145
- it('escapes version to prevent injection', () => {
146
- const html = renderServerRoot({ version: '<script>alert(1)</script>' });
147
- assert.doesNotMatch(html, /<script>alert\(1\)<\/script>/);
148
- assert.match(html, /&lt;script&gt;/);
149
- });
150
-
151
- // Regression for token re-scanning (#433 review thread): if the
152
- // renderer ran a chain of sequential .replace() calls, a value
153
- // containing a literal `{{actions}}` would land inside the subtitle
154
- // and then get expanded by the later `.replace(/{{actions}}/g, ...)`,
155
- // letting any pod owner inject other template fragments via their
156
- // singleUserName. The single-pass substitution prevents that.
157
- it('does not re-scan substituted values for further template tokens', () => {
158
- const html = renderServerRoot({
159
- version: '1.0.0',
160
- singleUser: true,
161
- idp: false,
162
- // The HTML escape only touches & < > " — { } pass through, so the
163
- // token would land in the output verbatim if the substitution were
164
- // multi-pass.
165
- singleUserName: 'evil{{actions}}name'
166
- });
167
- assert.match(html, /Personal pod for evil\{\{actions\}\}name/,
168
- 'singleUserName containing a template token should appear as plain text, not be re-templated');
169
- // Sanity: the real {{actions}} slot is still resolved (Docs link is always present).
170
- assert.match(html, /href="https:\/\/javascriptsolidserver\.github\.io\/docs/);
171
- });
172
-
173
- // Regression for the `$&` substitution gotcha (#433): a string used as
174
- // the second argument of String.prototype.replace interprets `$&`,
175
- // `$1`, etc. as substitution patterns. Interpolated values can contain
176
- // `$` (notably a singleUserName), so the renderer uses the function
177
- // form of replace instead. Asserting the literal `$&` survives the
178
- // round-trip would mean it survived as plain text.
179
- it('preserves $-patterns in singleUserName instead of treating them as replacement specials', () => {
180
- const html = renderServerRoot({
181
- version: '1.0.0',
182
- singleUser: true,
183
- idp: false,
184
- singleUserName: 'foo$&bar'
185
- });
186
- // The HTML escape converts `&` to `&amp;`; the rest must stay verbatim,
187
- // not be replaced by the matched template token.
188
- assert.match(html, /Personal pod for foo\$&amp;bar/,
189
- 'singleUserName containing "$&" should land as-is, not trigger String.replace substitution');
190
- assert.doesNotMatch(html, /\{\{subtitle\}\}/, 'subtitle token should be fully consumed');
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
+ );
191
248
  });
192
249
  });