forked from coinos/coinosv3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.js
More file actions
38 lines (34 loc) · 1.31 KB
/
Copy pathdev.js
File metadata and controls
38 lines (34 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Dev server: rebuilds the inlined bundle on every request so you just refresh
// the browser to see changes. Same output as `bun run build`, unminified.
import { buildHtml, buildJsQr } from './build.js';
const port = Number(process.env.PORT || 5173);
Bun.serve({
port,
async fetch(req) {
try {
const path = new URL(req.url).pathname;
if (path === '/jsqr.js') {
return new Response(await buildJsQr({ minify: false }), {
headers: { 'content-type': 'text/javascript; charset=utf-8' },
});
}
const loc = path.match(/^\/locales\/([a-z]{2})\.json$/);
if (loc) {
const f = Bun.file('src/locales/' + loc[1] + '.json');
return (await f.exists())
? new Response(f, { headers: { 'content-type': 'application/json; charset=utf-8' } })
: new Response('{}', { status: 404, headers: { 'content-type': 'application/json' } });
}
const html = await buildHtml({ minify: false });
return new Response(html, {
headers: { 'content-type': 'text/html; charset=utf-8' },
});
} catch (e) {
return new Response(`Build error:\n\n${e.stack || e}`, {
status: 500,
headers: { 'content-type': 'text/plain; charset=utf-8' },
});
}
},
});
console.log(`dev server → http://localhost:${port}`);