Add cors and content-type
This commit is contained in:
parent
dcd0c212b9
commit
0d293c8701
2 changed files with 14 additions and 2 deletions
0
cli.ts
Normal file → Executable file
0
cli.ts
Normal file → Executable file
16
server.ts
Executable file → Normal file
16
server.ts
Executable file → Normal file
|
@ -6,6 +6,13 @@ export async function processRequest(
|
||||||
runner = Deno.run,
|
runner = Deno.run,
|
||||||
fetcher = fetch,
|
fetcher = fetch,
|
||||||
): Promise<Response> {
|
): Promise<Response> {
|
||||||
|
if (req.method == "OPTIONS") {
|
||||||
|
return new Response(undefined, {
|
||||||
|
headers: {
|
||||||
|
"Access-Control-Allow-Origin": "*",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
if (req.method != "GET") {
|
if (req.method != "GET") {
|
||||||
return new Response(undefined, { status: 405 });
|
return new Response(undefined, { status: 405 });
|
||||||
}
|
}
|
||||||
|
@ -44,7 +51,12 @@ async function bundle(
|
||||||
const output = await process.output();
|
const output = await process.output();
|
||||||
const status = await process.status();
|
const status = await process.status();
|
||||||
if (status.success) {
|
if (status.success) {
|
||||||
return new Response(output);
|
return new Response(output, {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "text/javascript",
|
||||||
|
"Access-Control-Allow-Origin": "*",
|
||||||
|
},
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
return new Response(
|
return new Response(
|
||||||
`console.error("bundler error - Failed to bundle ${path}");`,
|
`console.error("bundler error - Failed to bundle ${path}");`,
|
||||||
|
@ -65,7 +77,7 @@ export async function serveBundles(hostpath: string, port: number) {
|
||||||
const response = await processRequest(req.request, hostpath);
|
const response = await processRequest(req.request, hostpath);
|
||||||
await req.respondWith(response);
|
await req.respondWith(response);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// console.error(err);
|
console.error(err);
|
||||||
await req.respondWith(Response.error());
|
await req.respondWith(Response.error());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue