Skip to content

Commit 943b930

Browse files
committed
feat: add media loading
1 parent 5cac2ef commit 943b930

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

packages/core/src/compile_commands.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,31 @@ export const runBunCompilation = async () => {
2020
await Bun.write(filesystem!.dist + "worker.ts", `
2121
import { serve } from 'bun';
2222
import index from './index.html';
23+
import { dirname } from 'path';
24+
25+
const BASE_MEDIA_PATH = "/media/";
26+
const EXE_DIR = dirname(process.execPath);
2327
2428
const server = serve({
2529
routes: {
2630
'/': index,
2731
},
32+
fetch(req) {
33+
const filepath = new URL(req.url).pathname;
34+
if (req.method === 'GET') {
35+
if (filepath.startsWith('/favicon')) {
36+
const filePath = \`\${ EXE_DIR }\${ BASE_MEDIA_PATH }favicon.svg\`;
37+
const file = Bun.file(filePath);
38+
return new Response(file);
39+
} else if (filepath.startsWith(BASE_MEDIA_PATH)) {
40+
const filePath = \`\${ EXE_DIR }\${ new URL(req.url).pathname }\`;
41+
const file = Bun.file(filePath);
42+
return new Response(file);
43+
}
44+
}
45+
46+
return new Response('Not Found', { status: 404 });
47+
},
2848
});
2949
`);
3050

0 commit comments

Comments
 (0)