From 0d293c87019d9a6f6b4de81b9cf1b421a3443c32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Thu, 1 Sep 2022 23:50:17 +0200 Subject: [PATCH] Add cors and content-type --- cli.ts | 0 server.ts | 16 ++++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) mode change 100644 => 100755 cli.ts mode change 100755 => 100644 server.ts diff --git a/cli.ts b/cli.ts old mode 100644 new mode 100755 diff --git a/server.ts b/server.ts old mode 100755 new mode 100644 index 9ccb9b4..901cf15 --- a/server.ts +++ b/server.ts @@ -6,6 +6,13 @@ export async function processRequest( runner = Deno.run, fetcher = fetch, ): Promise { + if (req.method == "OPTIONS") { + return new Response(undefined, { + headers: { + "Access-Control-Allow-Origin": "*", + }, + }); + } if (req.method != "GET") { return new Response(undefined, { status: 405 }); } @@ -44,7 +51,12 @@ async function bundle( const output = await process.output(); const status = await process.status(); if (status.success) { - return new Response(output); + return new Response(output, { + headers: { + "Content-Type": "text/javascript", + "Access-Control-Allow-Origin": "*", + }, + }); } else { return new Response( `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); await req.respondWith(response); } catch (err) { - // console.error(err); + console.error(err); await req.respondWith(Response.error()); } }