Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions insight/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ function serveStaticFile(pathname) {
// ── Server (dual runtime) ────────────────────────────────

const indexHTML = readFileSync(join(DIST_DIR, "index.html"), "utf8");
const API_JSON_HEADERS = { "Content-Type": "application/json" };

if (isBun) {
// Bun: use Bun.serve
Expand All @@ -597,7 +598,7 @@ if (isBun) {
const data = route(req.method, url.pathname, url.searchParams);
if (data !== null) {
return new Response(JSON.stringify(data), {
headers: { "Content-Type": "application/json", "Access-Control-Allow-Origin": "*" },
headers: API_JSON_HEADERS,
});
}
if (url.pathname.startsWith("/assets/") || url.pathname.match(/\.\w{2,4}$/)) {
Expand All @@ -613,8 +614,6 @@ if (isBun) {
// Node: use http.createServer
const server = createHttpServer((req, res) => {
const url = new URL(req.url, `http://localhost:${PORT}`);
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Methods", "GET, DELETE, OPTIONS");
if (req.method === "OPTIONS") { res.writeHead(204); res.end(); return; }

const data = route(req.method, url.pathname, url.searchParams);
Expand Down
Loading