From 02d313c3319e124665905556b2fa9f50e960b4d2 Mon Sep 17 00:00:00 2001 From: d9k Date: Thu, 14 Dec 2023 02:33:08 +0500 Subject: [PATCH] #288 JSON import fix for dev mode --- .vscode/launch.json | 18 ++++++++++++++++++ lib/middleware/compiler.ts | 15 ++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index e3abcfed..8a59dcba 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -19,6 +19,24 @@ "--allow-all" ], "attachSimplePort": 9229 + }, + { + "name": "citations-supabase-deno", + "request": "launch", + "type": "node", + "program": "server.tsx", + "cwd": "/home/d9k/cr/demo/citations-supabase-demo", + "runtimeExecutable": "${env:HOME}/.deno/bin/deno", + "runtimeArgs": [ + "run", + "--no-npm", + "--inspect", + "--allow-all", + "--no-check", + // "--watch" + ], + "args": [], + "attachSimplePort": 9229 } ] } diff --git a/lib/middleware/compiler.ts b/lib/middleware/compiler.ts index 79e2bb55..5a246a75 100644 --- a/lib/middleware/compiler.ts +++ b/lib/middleware/compiler.ts @@ -26,7 +26,20 @@ export const compiler = (options: CompilerOptions) => { const path = !isRemoteSource ? join(root, pathname) : pathname; const url = !isRemoteSource ? toFileUrl(path) : new URL(pathname); - const isCompilerTarget = [".ts", ".tsx", ".js", ".jsx"].includes(extension); + const isCompilerTarget = [".ts", ".tsx", ".js", ".jsx", ".json"].includes(extension); + const isJson = [".json"].includes(extension); + + if (method === "GET" && isJson) { + const bytes = await fetch(url).then((response) => response.arrayBuffer()); + const source = new TextDecoder().decode(bytes); + + return new Response(source, { + status: 200, + headers: { + "content-type": "application/json; charset=utf-8", + }, + }); + } if (method === "GET" && isCompilerTarget) { const bytes = await fetch(url).then((response) => response.arrayBuffer());