-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserve-visualizer.ts
More file actions
56 lines (45 loc) · 1.29 KB
/
serve-visualizer.ts
File metadata and controls
56 lines (45 loc) · 1.29 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* Simple static file server for the maze visualizer
* Serves files to avoid CORS issues with local file:// protocol
*/
const PORT = 3000;
const server = Bun.serve({
port: PORT,
async fetch(req) {
const url = new URL(req.url);
let filePath = url.pathname;
// Default to visualizer.html
if (filePath === '/') {
filePath = '/visualizer.html';
}
// Construct file path
const file = Bun.file(`.${filePath}`);
const exists = await file.exists();
if (!exists) {
return new Response('Not Found', { status: 404 });
}
// Serve the file
return new Response(file);
},
});
console.log('\n🎨 Maze Visualizer Server');
console.log('=' .repeat(50));
console.log(`✓ Server running at: http://localhost:${PORT}`);
console.log(`✓ Opening browser...`);
console.log(`\nPress Ctrl+C to stop the server\n`);
// Try to open the browser
const openCommands = {
darwin: 'open',
linux: 'xdg-open',
win32: 'start'
};
const platform = process.platform as keyof typeof openCommands;
const openCmd = openCommands[platform] || 'open';
try {
await Bun.spawn([openCmd, `http://localhost:${PORT}`], {
stdout: 'ignore',
stderr: 'ignore',
});
} catch (error) {
console.log(`Please open http://localhost:${PORT} in your browser`);
}