- Add favicon.svg: a crescent moon on a dark rounded tile - Link it from host/web/index.html as the page icon - serve.mjs: allow /favicon.svg through the path filter and serve it as image/svg+xml
This commit is contained in:
1 parent
1871d50a3e
commit
c1c4349584
3 files changed
+32
-2
No files matched your search
+3
-2
@@ -7,7 +7,7 @@ import { join, extname, normalize } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const ROOT = join(fileURLToPath(import.meta.url), '..', '..');
|
||||
const MIME = { '.html': 'text/html', '.mjs': 'text/javascript', '.js': 'text/javascript', '.json': 'application/json', '.wasm': 'application/wasm' };
|
||||
const MIME = { '.html': 'text/html', '.mjs': 'text/javascript', '.js': 'text/javascript', '.json': 'application/json', '.wasm': 'application/wasm', '.svg': 'image/svg+xml' };
|
||||
const ALLOWED = ['host/', 'config/', 'build/'];
|
||||
|
||||
export function serve(port = 0) {
|
||||
@@ -16,7 +16,8 @@ export function serve(port = 0) {
|
||||
let p = decodeURIComponent(new URL(req.url, 'http://x').pathname);
|
||||
if (p === '/') p = '/host/web/index.html';
|
||||
const rel = normalize(p).replace(/^\/+/, '');
|
||||
if (rel.includes('..') || !ALLOWED.some((a) => rel.startsWith(a)) || rel.startsWith('host/node_modules')) { res.writeHead(404).end('not found'); return; }
|
||||
const isAllowed = rel === 'favicon.svg' || ALLOWED.some((a) => rel.startsWith(a));
|
||||
if (rel.includes('..') || !isAllowed || rel.startsWith('host/node_modules')) { res.writeHead(404).end('not found'); return; }
|
||||
const body = await readFile(join(ROOT, rel));
|
||||
res.writeHead(200, { 'content-type': MIME[extname(rel)] ?? 'application/octet-stream', 'cache-control': 'no-store' }).end(body);
|
||||
} catch { res.writeHead(404).end('not found'); }
|
||||
|
||||
Reference in new issue
Block a user