Initial commit
This commit is contained in:
commit
ae2c99d71a
9 files changed
+213
No files matched your search
@@ -0,0 +1,6 @@
|
||||
import { mkdir, copyFile } from 'node:fs/promises';
|
||||
await mkdir('dist', { recursive: true });
|
||||
for (const file of ['index.html', 'styles.css', 'app.js', 'content.js', 'favicon.svg']) {
|
||||
await copyFile(file, `dist/${file}`);
|
||||
}
|
||||
console.log('Built static site in dist/');
|
||||
@@ -0,0 +1,14 @@
|
||||
import { createServer } from 'node:http';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
const port = Number(process.env.PORT || 4173);
|
||||
const files = new Map([['/', 'index.html'], ['/index.html', 'index.html'], ['/styles.css', 'styles.css'], ['/app.js', 'app.js'], ['/content.js', 'content.js'], ['/favicon.svg', 'favicon.svg']]);
|
||||
const mime = { html: 'text/html', css: 'text/css', js: 'text/javascript', svg: 'image/svg+xml' };
|
||||
createServer(async (req, res) => {
|
||||
const file = files.get(new URL(req.url, 'http://localhost').pathname);
|
||||
if (!file) { res.writeHead(404); return res.end('Not found'); }
|
||||
try {
|
||||
const body = await readFile(new URL(`../${file}`, import.meta.url));
|
||||
res.writeHead(200, { 'Content-Type': `${mime[file.split('.').pop()]}; charset=utf-8`, 'Cache-Control': 'no-cache', 'X-Content-Type-Options': 'nosniff' });
|
||||
res.end(body);
|
||||
} catch { res.writeHead(500); res.end('Unable to read file'); }
|
||||
}).listen(port, '127.0.0.1', () => console.log(`Local: http://127.0.0.1:${port}`));
|
||||
Reference in new issue
Block a user