@johnhenry/sitefile 0.0.1 → 0.0.3
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/CHANGELOG.md +480 -3
- package/README.md +70 -21
- package/lib/src/archive-writers.d.ts +12 -2
- package/lib/src/archive-writers.js +53 -10
- package/lib/src/canonical.d.ts +16 -0
- package/lib/src/canonical.js +46 -0
- package/lib/src/car.d.ts +34 -0
- package/lib/src/car.js +203 -0
- package/lib/src/checklinks.js +8 -2
- package/lib/src/cli/bake.js +4 -3
- package/lib/src/cli/build-image.d.ts +1 -0
- package/lib/src/cli/build-image.js +1 -0
- package/lib/src/cli/common.js +4 -1
- package/lib/src/cli/hosts.d.ts +5 -0
- package/lib/src/cli/hosts.js +78 -0
- package/lib/src/cli/images.js +23 -5
- package/lib/src/cli/import-config.d.ts +2 -0
- package/lib/src/cli/import-config.js +56 -0
- package/lib/src/cli/index.d.ts +3 -1
- package/lib/src/cli/index.js +31 -2
- package/lib/src/cli/integrity.d.ts +2 -0
- package/lib/src/cli/integrity.js +77 -0
- package/lib/src/cli/network.d.ts +7 -0
- package/lib/src/cli/network.js +14 -3
- package/lib/src/cli/serve-keys.d.ts +39 -0
- package/lib/src/cli/serve-keys.js +106 -0
- package/lib/src/cli/serve-worker.js +46 -8
- package/lib/src/cli/servers.d.ts +124 -1
- package/lib/src/cli/servers.js +705 -62
- package/lib/src/cli/up.d.ts +2 -0
- package/lib/src/cli/up.js +193 -0
- package/lib/src/cli/watch.d.ts +14 -1
- package/lib/src/cli/watch.js +20 -3
- package/lib/src/cli.js +138 -18
- package/lib/src/csp.d.ts +17 -0
- package/lib/src/csp.js +52 -0
- package/lib/src/dictionary.d.ts +16 -0
- package/lib/src/dictionary.js +89 -0
- package/lib/src/epub.d.ts +5 -0
- package/lib/src/epub.js +113 -0
- package/lib/src/errors.d.ts +22 -9
- package/lib/src/errors.js +20 -1
- package/lib/src/executor.d.ts +31 -1
- package/lib/src/executor.js +192 -22
- package/lib/src/explain.js +33 -3
- package/lib/src/export-for.d.ts +42 -0
- package/lib/src/export-for.js +466 -0
- package/lib/src/export-formats.d.ts +2 -2
- package/lib/src/export-formats.js +52 -2
- package/lib/src/fingerprint.d.ts +3 -1
- package/lib/src/fingerprint.js +32 -5
- package/lib/src/host-config.d.ts +34 -0
- package/lib/src/host-config.js +645 -0
- package/lib/src/hosts.d.ts +47 -0
- package/lib/src/hosts.js +106 -0
- package/lib/src/index.d.ts +1 -1
- package/lib/src/index.js +1 -1
- package/lib/src/integrity.d.ts +115 -0
- package/lib/src/integrity.js +273 -0
- package/lib/src/language/ast.d.ts +116 -3
- package/lib/src/language/ast.js +7 -1
- package/lib/src/language/parser.js +176 -7
- package/lib/src/language/validate.js +21 -0
- package/lib/src/links.d.ts +33 -0
- package/lib/src/links.js +271 -3
- package/lib/src/lint.d.ts +1 -1
- package/lib/src/lint.js +26 -1
- package/lib/src/mime-data.d.ts +2 -0
- package/lib/src/mime-data.js +92 -0
- package/lib/src/oci.d.ts +20 -2
- package/lib/src/oci.js +70 -28
- package/lib/src/outdated.d.ts +3 -0
- package/lib/src/outdated.js +4 -4
- package/lib/src/planner.d.ts +69 -2
- package/lib/src/planner.js +150 -8
- package/lib/src/plugins/cache.d.ts +11 -0
- package/lib/src/plugins/cache.js +29 -0
- package/lib/src/plugins/host.d.ts +51 -2
- package/lib/src/plugins/host.js +144 -18
- package/lib/src/plugins/wasm.js +1 -3
- package/lib/src/portable.d.ts +8 -0
- package/lib/src/portable.js +47 -0
- package/lib/src/precache.d.ts +33 -0
- package/lib/src/precache.js +75 -0
- package/lib/src/precompress.d.ts +19 -0
- package/lib/src/precompress.js +35 -0
- package/lib/src/qr.d.ts +18 -0
- package/lib/src/qr.js +372 -0
- package/lib/src/registry-ops.js +4 -2
- package/lib/src/reload-client.d.ts +2 -0
- package/lib/src/reload-client.js +304 -0
- package/lib/src/resources/archive.d.ts +36 -0
- package/lib/src/resources/archive.js +338 -67
- package/lib/src/resources/convert.js +3 -1
- package/lib/src/resources/https.d.ts +9 -1
- package/lib/src/resources/https.js +36 -0
- package/lib/src/resources/network.d.ts +25 -3
- package/lib/src/resources/network.js +77 -6
- package/lib/src/secrets.d.ts +12 -3
- package/lib/src/secrets.js +18 -5
- package/lib/src/serve-auth.d.ts +32 -0
- package/lib/src/serve-auth.js +112 -0
- package/lib/src/serve-rules.d.ts +83 -7
- package/lib/src/serve-rules.js +264 -53
- package/lib/src/server.d.ts +437 -10
- package/lib/src/server.js +1236 -52
- package/lib/src/servers-file.d.ts +36 -0
- package/lib/src/servers-file.js +101 -0
- package/lib/src/servers.d.ts +109 -7
- package/lib/src/servers.js +151 -29
- package/lib/src/single-file.d.ts +12 -0
- package/lib/src/single-file.js +147 -0
- package/lib/src/site.d.ts +54 -0
- package/lib/src/site.js +204 -6
- package/lib/src/store.js +9 -5
- package/lib/src/swbn.d.ts +10 -0
- package/lib/src/swbn.js +86 -0
- package/lib/src/toml.d.ts +17 -0
- package/lib/src/toml.js +323 -0
- package/lib/src/wacz.d.ts +6 -0
- package/lib/src/wacz.js +96 -0
- package/lib/src/warc.d.ts +28 -0
- package/lib/src/warc.js +252 -0
- package/lib/src/watch.d.ts +12 -1
- package/lib/src/watch.js +67 -1
- package/lib/src/wbn.d.ts +9 -1
- package/lib/src/wbn.js +23 -33
- package/lib/src/zstd.d.ts +4 -0
- package/lib/src/zstd.js +328 -0
- package/package.json +1 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { encodeQr, qrTerminal } from '../qr.js';
|
|
3
|
+
import { formatUrl, networkUrls } from '../server.js';
|
|
4
|
+
/** What a key does (letters in either case; Ctrl-C and Ctrl-D quit), or undefined. */
|
|
5
|
+
export function keyAction(byte) {
|
|
6
|
+
if (byte === 3 || byte === 4)
|
|
7
|
+
return 'quit';
|
|
8
|
+
switch (String.fromCharCode(byte).toLowerCase()) {
|
|
9
|
+
case 'o':
|
|
10
|
+
return 'open';
|
|
11
|
+
case 'u':
|
|
12
|
+
return 'urls';
|
|
13
|
+
case 'r':
|
|
14
|
+
return 'restart';
|
|
15
|
+
case 'c':
|
|
16
|
+
return 'clear';
|
|
17
|
+
case 'q':
|
|
18
|
+
return 'quit';
|
|
19
|
+
case 'h':
|
|
20
|
+
return 'help';
|
|
21
|
+
default:
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export const KEYS_HINT = 'Press h for keys\n';
|
|
26
|
+
export const KEYS_HELP = 'Keys: o open in the browser, u show the URLs, r rebuild (--watch) or re-read the directory, c clear the screen, q quit, h this help\n';
|
|
27
|
+
export const CLEAR = '\x1b[2J\x1b[3J\x1b[H';
|
|
28
|
+
const isWildcard = (h) => h === '0.0.0.0' || h === '::';
|
|
29
|
+
/**
|
|
30
|
+
* The URLs to show (below `serve --base`, `https://` for a TLS server): the local one, and when bound to every
|
|
31
|
+
* interface the same network URLs as the start line (one per interface address, IPv4 first).
|
|
32
|
+
*/
|
|
33
|
+
export function serveUrls(host, port, base = '/', scheme = 'http') {
|
|
34
|
+
const path = base.slice(1);
|
|
35
|
+
const local = formatUrl(host, port, scheme) + path;
|
|
36
|
+
return { local, network: isWildcard(host) ? networkUrls(host, port, scheme).map((u) => u + path) : [] };
|
|
37
|
+
}
|
|
38
|
+
/** `u`: the URLs, and a QR code of the first network URL when there is one. */
|
|
39
|
+
export function urlsText(urls) {
|
|
40
|
+
let out = ` Local: ${urls.local}\n`;
|
|
41
|
+
for (const n of urls.network)
|
|
42
|
+
out += ` Network: ${n}\n`;
|
|
43
|
+
if (urls.network[0] !== undefined)
|
|
44
|
+
out += qrText(urls.network[0]);
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
/** `--qr`: the URL and its QR code. */
|
|
48
|
+
export function qrText(url) {
|
|
49
|
+
const code = encodeQr(url);
|
|
50
|
+
return code ? qrTerminal(code) : '';
|
|
51
|
+
}
|
|
52
|
+
/** `--open=<path>` (or `--open`, `/`) joined to the server's URL. */
|
|
53
|
+
export function openUrl(base, path) {
|
|
54
|
+
return base + path.replace(/^\/+/, '');
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Open `url` in the browser: `$BROWSER` when set (a program, run with the URL as its only argument, no
|
|
58
|
+
* shell), else `open` (macOS), `rundll32 url.dll,FileProtocolHandler` (Windows) or `xdg-open`. A failure is
|
|
59
|
+
* a warning: the server keeps running.
|
|
60
|
+
*/
|
|
61
|
+
export function openBrowser(url, warn) {
|
|
62
|
+
const browser = process.env['BROWSER'];
|
|
63
|
+
const [cmd, args] = browser !== undefined && browser !== ''
|
|
64
|
+
? [browser, [url]]
|
|
65
|
+
: process.platform === 'darwin'
|
|
66
|
+
? ['open', [url]]
|
|
67
|
+
: process.platform === 'win32'
|
|
68
|
+
? ['rundll32', ['url.dll,FileProtocolHandler', url]]
|
|
69
|
+
: ['xdg-open', [url]];
|
|
70
|
+
try {
|
|
71
|
+
const child = spawn(cmd, args, { stdio: 'ignore', detached: true });
|
|
72
|
+
child.on('error', (e) => warn(`cannot open the browser (${cmd}): ${e.message}`));
|
|
73
|
+
child.unref();
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
warn(`cannot open the browser (${cmd}): ${e.message}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Read single keys from stdin while serving: when stdin is a terminal (raw mode), or when
|
|
81
|
+
* `SITEFILE_SERVE_KEYS=1` (tests drive it through a pipe). Returns a function that stops reading and
|
|
82
|
+
* restores the terminal, or undefined when keys are off.
|
|
83
|
+
*/
|
|
84
|
+
export function readKeys(onAction) {
|
|
85
|
+
const tty = !!process.stdin.isTTY;
|
|
86
|
+
if (!tty && process.env['SITEFILE_SERVE_KEYS'] !== '1')
|
|
87
|
+
return undefined;
|
|
88
|
+
if (tty)
|
|
89
|
+
process.stdin.setRawMode(true);
|
|
90
|
+
const onData = (chunk) => {
|
|
91
|
+
for (const b of chunk) {
|
|
92
|
+
const a = keyAction(b);
|
|
93
|
+
if (a)
|
|
94
|
+
onAction(a);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
process.stdin.on('data', onData);
|
|
98
|
+
process.stdin.resume();
|
|
99
|
+
return () => {
|
|
100
|
+
process.stdin.off('data', onData);
|
|
101
|
+
if (tty)
|
|
102
|
+
process.stdin.setRawMode(false);
|
|
103
|
+
process.stdin.pause();
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=serve-keys.js.map
|
|
@@ -1,36 +1,74 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Detached server process spawned by `sitefile serve -d` / `restart`.
|
|
3
3
|
// Usage: node serve-worker.js <server id>. State and logs live in $SITEFILE_HOME/servers.
|
|
4
|
+
import { readFile } from 'node:fs/promises';
|
|
4
5
|
import { SitefileError } from '../errors.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
6
|
+
import { BasicAuth, parseHtpasswd } from '../serve-auth.js';
|
|
7
|
+
import { closeServer, createSiteServer, formatUrl, jsonLogLine, listen, parseCidr, parseThrottle, startedLogLine, stoppedLogLine, routingFor } from '../server.js';
|
|
8
|
+
import { loadServedTree, servedLastModified, ServerRegistry, loadServedSite, checkSiteFiles } from '../servers.js';
|
|
9
|
+
let json = false; // `--log-format json`: every line is a JSON object
|
|
10
|
+
const stamp = (m) => {
|
|
11
|
+
const ts = new Date().toISOString();
|
|
12
|
+
process.stdout.write(json ? `${m.startsWith('{') ? m : jsonLogLine(ts, m)}\n` : `${ts} ${m}\n`);
|
|
13
|
+
};
|
|
8
14
|
async function main() {
|
|
9
15
|
const id = process.argv[2] ?? '';
|
|
10
16
|
const reg = await ServerRegistry.open();
|
|
11
17
|
const state = await reg.read(id);
|
|
12
18
|
if (!state)
|
|
13
19
|
throw new SitefileError('E_SERVER', `no state for server '${id}'`);
|
|
20
|
+
json = state.logFormat === 'json';
|
|
14
21
|
try {
|
|
15
|
-
const
|
|
16
|
-
|
|
22
|
+
const left = state.expires === undefined ? undefined : Date.parse(state.expires) - Date.now();
|
|
23
|
+
if (left !== undefined && left <= 0)
|
|
24
|
+
throw new SitefileError('E_SERVER', `server expired at ${state.expires} (--stop-after)`);
|
|
25
|
+
const ipRules = state.allowIp !== undefined || state.denyIp !== undefined ? { allow: (state.allowIp ?? []).flatMap((t) => parseCidr(t) ?? []), deny: (state.denyIp ?? []).flatMap((t) => parseCidr(t) ?? []) } : undefined;
|
|
26
|
+
const loopback = state.bind.host === 'localhost' || state.bind.host === '::1' || /^127\./.test(state.bind.host);
|
|
27
|
+
const { tree, content } = await loadServedSite(reg.store, state.source, { keepOsMetadata: !!state.keepOsMetadata, warn: (m) => stamp(`warning: ${m}`) });
|
|
28
|
+
if (routingFor(state)?.siteFiles !== false)
|
|
29
|
+
checkSiteFiles(tree, !!state.strictSiteFiles, (m) => stamp(`warning: ${m}`), content);
|
|
30
|
+
const modified = await servedLastModified(reg.store, state.source);
|
|
31
|
+
const authEntries = [...(state.auth ?? []), ...(state.authFile !== undefined ? parseHtpasswd(await readFile(state.authFile, 'utf8'), state.authFile) : [])];
|
|
32
|
+
const server = createSiteServer(tree, { spa: state.spa, allowedHosts: state.allowedHosts ?? [], cors: !!state.cors, ...(state.isolate ? { isolate: state.isolate } : {}), ...(state.cache ? { cache: state.cache } : {}), ...(json ? { logFormat: 'json' } : {}), logIp: !!state.logIp, quiet: !!state.quiet, ...(authEntries.length > 0 || state.authFile !== undefined ? { auth: new BasicAuth(authEntries) } : {}), ...(state.maxConnectionsPerIp ? { maxConnectionsPerIp: state.maxConnectionsPerIp } : {}), ...(state.hideBase ? { hideBase: true } : {}), ...(ipRules ? { ipRules } : {}), ...(loopback ? {} : { noindex: true }), clientInfo: true, compress: !!state.compress, ...(state.mime ? { mime: new Map(Object.entries(state.mime)) } : {}), ...(state.throttle !== undefined && parseThrottle(state.throttle) ? { throttle: parseThrottle(state.throttle) } : {}), ...(state.tlsCert !== undefined && state.tlsKey !== undefined ? { tls: { cert: await readFile(state.tlsCert), key: await readFile(state.tlsKey) } } : {}), serverId: id, lastModified: () => modified, log: stamp, ...(content ? { content } : {}), ...(state.country !== undefined ? { country: state.country } : {}), ...(state.spaExclude ? { spaExclude: state.spaExclude } : {}), ...(state.spaFallback !== undefined ? { spaFallback: state.spaFallback } : {}), ...(state.base !== undefined ? { base: state.base } : {}), ...(state.rewriteBase !== undefined ? { rewriteBase: state.rewriteBase } : {}), ...(routingFor(state) ? { profile: routingFor(state) } : {}) });
|
|
17
33
|
const addr = await listen(server, state.bind.host, state.bind.port);
|
|
18
34
|
await reg.update(id, { pid: process.pid, host: addr.host, port: addr.port, ready: true, error: undefined });
|
|
19
|
-
|
|
35
|
+
const root = formatUrl(addr.host, addr.port, state.tlsCert !== undefined ? 'https' : 'http');
|
|
36
|
+
const url = `${root}${(state.base ?? '/').slice(1)}`;
|
|
37
|
+
if (json)
|
|
38
|
+
stamp(startedLogLine(new Date().toISOString(), state.image, tree.size, url));
|
|
39
|
+
else
|
|
40
|
+
stamp(`serving ${state.image} (${tree.size} files) at ${url}`);
|
|
20
41
|
const stop = (signal) => () => {
|
|
21
|
-
|
|
42
|
+
if (json)
|
|
43
|
+
stamp(stoppedLogLine(new Date().toISOString(), signal));
|
|
44
|
+
else
|
|
45
|
+
stamp(`received ${signal}, shutting down`);
|
|
22
46
|
void closeServer(server).then(async () => {
|
|
23
47
|
await reg.update(id, { ready: false }).catch(() => undefined);
|
|
24
48
|
process.exit(0);
|
|
25
49
|
});
|
|
26
50
|
setTimeout(() => process.exit(0), 3000).unref();
|
|
27
51
|
};
|
|
52
|
+
if (left !== undefined) {
|
|
53
|
+
setTimeout(() => {
|
|
54
|
+
if (json)
|
|
55
|
+
stamp(stoppedLogLine(new Date().toISOString(), 'expired'));
|
|
56
|
+
else
|
|
57
|
+
stamp('--stop-after reached, shutting down');
|
|
58
|
+
void closeServer(server).then(async () => {
|
|
59
|
+
await reg.update(id, { ready: false }).catch(() => undefined);
|
|
60
|
+
process.exit(0);
|
|
61
|
+
});
|
|
62
|
+
setTimeout(() => process.exit(0), 3000).unref();
|
|
63
|
+
}, Math.min(left, 2 ** 31 - 1));
|
|
64
|
+
}
|
|
28
65
|
process.on('SIGTERM', stop('SIGTERM'));
|
|
29
66
|
process.on('SIGINT', stop('SIGINT'));
|
|
30
67
|
}
|
|
31
68
|
catch (e) {
|
|
32
69
|
const message = e instanceof SitefileError ? `error[${e.code}]: ${e.message}` : `error: ${e.message}`;
|
|
33
|
-
|
|
70
|
+
const ts = new Date().toISOString();
|
|
71
|
+
process.stderr.write(json ? `${jsonLogLine(ts, message)}\n` : `${ts} ${message}\n`);
|
|
34
72
|
await reg.update(id, { pid: 0, ready: false, error: message }).catch(() => undefined);
|
|
35
73
|
process.exit(1);
|
|
36
74
|
}
|
package/lib/src/cli/servers.d.ts
CHANGED
|
@@ -1,14 +1,137 @@
|
|
|
1
|
+
import { type CachePreview, type HostProfileName, type HtmlHandling } from '../server.js';
|
|
1
2
|
import { ServerRegistry, type ServerState } from '../servers.js';
|
|
2
|
-
import { type
|
|
3
|
+
import { type AuthEntry } from '../serve-auth.js';
|
|
4
|
+
import type { Plan } from '../planner.js';
|
|
5
|
+
import { Store } from '../store.js';
|
|
6
|
+
import { type Command, type ParsedValues } from './common.js';
|
|
3
7
|
/** `-p` value: `port`, `host:port` or `[v6]:port`. Default bind is 127.0.0.1 with a free port. */
|
|
4
8
|
export declare function parsePublish(spec: string | undefined): {
|
|
5
9
|
host: string;
|
|
6
10
|
port: number;
|
|
7
11
|
};
|
|
12
|
+
/** `--spa`, `--spa-exclude` and `--spa-fallback` (which implies `--spa`), as server options. */
|
|
13
|
+
export declare function spaOptions(v: ParsedValues): {
|
|
14
|
+
spa: boolean;
|
|
15
|
+
spaExclude?: string[];
|
|
16
|
+
spaFallback?: string;
|
|
17
|
+
};
|
|
18
|
+
/** `--base`: the path prefix to serve under (`/repo/`), or undefined for `/`. */
|
|
19
|
+
export declare function parseBase(v: string | undefined): string | undefined;
|
|
20
|
+
/** The path of an EXPORT BASE that is an http(s) URL (`https://user.github.io/repo/` → `/repo/`), else undefined. */
|
|
21
|
+
export declare function exportBasePath(exportBase: string | undefined): string | undefined;
|
|
22
|
+
/** `--rewrite-base <url>`: the production URL, normalized; usage error when it is not an http(s) URL. */
|
|
23
|
+
export declare function parseRewriteBase(v: string | undefined): string | undefined;
|
|
24
|
+
/** A build's production URL (`serve --watch`): its EXPORT BASE when that is an http(s) URL, else the first SITEMAP or FEED BASE. */
|
|
25
|
+
export declare function productionUrl(plan: Plan): string | undefined;
|
|
26
|
+
/** `--host-profile` and `--html-handling`, checked: the names, or usage errors. */
|
|
27
|
+
export declare function profileOptions(v: ParsedValues): {
|
|
28
|
+
hostProfile?: HostProfileName;
|
|
29
|
+
htmlHandling?: HtmlHandling;
|
|
30
|
+
};
|
|
31
|
+
/** `--country`: an ISO 3166-1 alpha-2 code (any case). */
|
|
32
|
+
export declare function parseCountry(v: string | undefined): string | undefined;
|
|
33
|
+
declare function isFile(p: string): Promise<boolean>;
|
|
34
|
+
/** An archive file source: labelled by its absolute path, stored by its real path. */
|
|
35
|
+
export declare function archiveSource(arg: string): Promise<{
|
|
36
|
+
label: string;
|
|
37
|
+
source: ServerState['source'];
|
|
38
|
+
}>;
|
|
39
|
+
/**
|
|
40
|
+
* A directory or archive file when `arg` looks like a path, else an image reference or ID, else an
|
|
41
|
+
* archive file by that name (`site.zip`). Whether a file is an archive is checked when it is loaded.
|
|
42
|
+
*/
|
|
43
|
+
export declare function resolveSource(store: Store, arg: string): Promise<{
|
|
44
|
+
label: string;
|
|
45
|
+
source: ServerState['source'];
|
|
46
|
+
}>;
|
|
47
|
+
/** What a detached server serves and how (`serve -d`, `sitefile up`). */
|
|
48
|
+
export interface DetachedServe {
|
|
49
|
+
readonly label: string;
|
|
50
|
+
readonly source: ServerState['source'];
|
|
51
|
+
readonly name?: string | undefined;
|
|
52
|
+
readonly bind: {
|
|
53
|
+
readonly host: string;
|
|
54
|
+
readonly port: number;
|
|
55
|
+
};
|
|
56
|
+
readonly spa: boolean;
|
|
57
|
+
/** `--spa-exclude`. */
|
|
58
|
+
readonly spaExclude?: readonly string[] | undefined;
|
|
59
|
+
/** `--spa-fallback`. */
|
|
60
|
+
readonly spaFallback?: string | undefined;
|
|
61
|
+
/** `--base` (normalized; undefined for `/`). */
|
|
62
|
+
readonly base?: string | undefined;
|
|
63
|
+
/** `--rewrite-base` (normalized). */
|
|
64
|
+
readonly rewriteBase?: string | undefined;
|
|
65
|
+
/** `--host-profile`. */
|
|
66
|
+
readonly hostProfile?: HostProfileName | undefined;
|
|
67
|
+
/** `--html-handling`. */
|
|
68
|
+
readonly htmlHandling?: HtmlHandling | undefined;
|
|
69
|
+
/** `--keep-os-metadata`. */
|
|
70
|
+
readonly keepOsMetadata?: boolean | undefined;
|
|
71
|
+
/** `--allowed-host` names. */
|
|
72
|
+
readonly allowedHosts?: readonly string[] | undefined;
|
|
73
|
+
/** `--cors`. */
|
|
74
|
+
readonly cors?: boolean | undefined;
|
|
75
|
+
/** `--isolate`: the COEP value. */
|
|
76
|
+
readonly isolate?: 'require-corp' | 'credentialless' | undefined;
|
|
77
|
+
/** `--max-age`, `--immutable`, `--max-age-html`. */
|
|
78
|
+
readonly cache?: CachePreview | undefined;
|
|
79
|
+
/** `--log-format json`. */
|
|
80
|
+
readonly logFormat?: 'json' | undefined;
|
|
81
|
+
/** `--log-ip`. */
|
|
82
|
+
readonly logIp?: boolean | undefined;
|
|
83
|
+
/** `--quiet`. */
|
|
84
|
+
readonly quiet?: boolean | undefined;
|
|
85
|
+
/** `--auth` verifiers. */
|
|
86
|
+
readonly auth?: AuthEntry[] | undefined;
|
|
87
|
+
/** `--auth-file`, an absolute path read at every start. */
|
|
88
|
+
readonly authFile?: string | undefined;
|
|
89
|
+
/** `--max-connections-per-ip` (absent: no limit). */
|
|
90
|
+
readonly maxConnectionsPerIp?: number | undefined;
|
|
91
|
+
/** `--random-route` prefix. */
|
|
92
|
+
readonly hideBase?: boolean | undefined;
|
|
93
|
+
/** `--allow-ip`, `--deny-ip` blocks as given. */
|
|
94
|
+
readonly allowIp?: string[] | undefined;
|
|
95
|
+
readonly denyIp?: string[] | undefined;
|
|
96
|
+
/** `--stop-after`: when the server stops (ISO time). */
|
|
97
|
+
readonly expires?: string | undefined;
|
|
98
|
+
/** `--compress`. */
|
|
99
|
+
readonly compress?: boolean | undefined;
|
|
100
|
+
/** `--throttle` as given. */
|
|
101
|
+
readonly throttle?: string | undefined;
|
|
102
|
+
/** `--mime`, `--mime-file`: extension → content type. */
|
|
103
|
+
readonly mime?: Record<string, string> | undefined;
|
|
104
|
+
/** `--tls-cert`, `--tls-key`, absolute paths. */
|
|
105
|
+
readonly tlsCert?: string | undefined;
|
|
106
|
+
readonly tlsKey?: string | undefined;
|
|
107
|
+
/** `--country`. */
|
|
108
|
+
readonly country?: string | undefined;
|
|
109
|
+
/** `--strict-site-files`. */
|
|
110
|
+
readonly strictSiteFiles?: boolean | undefined;
|
|
111
|
+
/** The servers file it belongs to (`sitefile up`). */
|
|
112
|
+
readonly project?: string | undefined;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* `serve -d`: check that the source loads, allocate an ID and name, record the server, start its worker and
|
|
116
|
+
* wait until it listens. On failure the record is removed.
|
|
117
|
+
*/
|
|
118
|
+
export declare function serveDetached(reg: ServerRegistry, d: DetachedServe, warn?: (m: string) => void): Promise<ServerState>;
|
|
119
|
+
/**
|
|
120
|
+
* `server restart`: stop `s` if it is running, then start it again with the same ID, name, source and
|
|
121
|
+
* requested bind address. On failure the record stays, marked not ready.
|
|
122
|
+
*/
|
|
123
|
+
export declare function restartDetached(reg: ServerRegistry, s: ServerState, graceMs: number): Promise<ServerState>;
|
|
124
|
+
/** `--proxy /prefix=url`: a path prefix (no trailing slash, except `/`) and an http(s) URL. */
|
|
125
|
+
export declare function parseProxyRoute(raw: string): {
|
|
126
|
+
prefix: string;
|
|
127
|
+
target: string;
|
|
128
|
+
};
|
|
8
129
|
/** SIGTERM, wait, then SIGKILL. Returns false if the server was not running. */
|
|
9
130
|
export declare function stopServer(reg: ServerRegistry, s: ServerState, graceMs: number): Promise<boolean>;
|
|
131
|
+
export declare function graceOf(v: ParsedValues): number;
|
|
10
132
|
/** The last n lines of text, each newline-terminated; a trailing newline is not an extra empty line. */
|
|
11
133
|
export declare function tailLines(text: string, n: number): string;
|
|
134
|
+
export { isFile };
|
|
12
135
|
/** Top-level: `sitefile serve`, `sitefile servers`. */
|
|
13
136
|
export declare const serverCommands: ReadonlyMap<string, Command>;
|
|
14
137
|
/** `sitefile server <ls|stop|rm|logs|restart>`. */
|