Skip to content

Commit

Permalink
exhibitionist-digital#288 JSON import fix for dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
d9k committed Dec 14, 2023
1 parent 18e51de commit 02d313c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
15 changes: 14 additions & 1 deletion lib/middleware/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 02d313c

Please sign in to comment.