/** * Simple static file server for testing paste variants. * * Usage: * bun run serve.ts * * Then open: * http://localhost:3456/paste-indexeddb.html * http://localhost:3456/paste-sqlite.html * http://localhost:3456/paste-nedb.html * * The SQLite variant REQUIRES HTTP (can't load .wasm from file://). * The IndexedDB and NeDB variants also work from file:// directly. */ const PORT = 3456; const mimeTypes: Record = { '.html': 'text/html', '.js': 'text/javascript', '.css': 'text/css', '.wasm': 'application/wasm', '.json': 'application/json', }; Bun.serve({ port: PORT, async fetch(req) { const url = new URL(req.url); let path = url.pathname; if (path === '/') path = '/index.html'; const filePath = './dist' + path; const file = Bun.file(filePath); if (!(await file.exists())) { return new Response('Not found', { status: 404 }); } const ext = path.substring(path.lastIndexOf('.')); const contentType = mimeTypes[ext] || 'application/octet-stream'; return new Response(file, { headers: { 'Content-Type': contentType }, }); }, }); console.log(`Serving paste/dist/ at http://localhost:${PORT}/`); console.log(` http://localhost:${PORT}/paste-indexeddb.html`); console.log(` http://localhost:${PORT}/paste-sqlite.html`); console.log(` http://localhost:${PORT}/paste-nedb.html`);