Jason Tudisco 6ebe02ad56 Initial commit: local-first browser sync library experiment
Four variants of the same sync library (IndexedDB, NeDB, SQLite WASM, sql.js)
plus a paste-bin demo app for testing multi-browser sync via shared folders.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-17 22:04:08 -06:00

53 lines
1.4 KiB
TypeScript

/**
* 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<string, string> = {
'.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`);