From b6eb2d6f9385fbc593830e9a93935edafd26db52 Mon Sep 17 00:00:00 2001 From: Trevor Baron Date: Sun, 5 May 2019 17:40:31 -0700 Subject: [PATCH 1/4] add back cors option --- bin/serve.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bin/serve.js b/bin/serve.js index 45e583f3..85db9d5a 100755 --- a/bin/serve.js +++ b/bin/serve.js @@ -176,7 +176,10 @@ const startEndpoint = (endpoint, config, args, previous) => { if (compress) { await compressionHandler(request, response); } - + if(args["--cors"]){ + response.setHeader("Access-Control-Allow-Origin", "*"); + } + return handler(request, response, config); }); @@ -344,6 +347,7 @@ const loadConfig = async (cwd, entry, args) => { '--no-clipboard': Boolean, '--no-compression': Boolean, '--symlinks': Boolean, + '--cors': Boolean, '-h': '--help', '-v': '--version', '-l': '--listen', @@ -353,6 +357,7 @@ const loadConfig = async (cwd, entry, args) => { '-n': '--no-clipboard', '-u': '--no-compression', '-S': '--symlinks', + '-C': '--cors', // This is deprecated and only for backwards-compatibility. '-p': '--listen' }); From 91d608bedd6ea7e23c0a53aacc632dd6d2a3fcae Mon Sep 17 00:00:00 2001 From: Trevor Baron Date: Sun, 5 May 2019 17:43:52 -0700 Subject: [PATCH 2/4] fix linting --- bin/serve.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/serve.js b/bin/serve.js index 85db9d5a..331455fc 100755 --- a/bin/serve.js +++ b/bin/serve.js @@ -176,10 +176,10 @@ const startEndpoint = (endpoint, config, args, previous) => { if (compress) { await compressionHandler(request, response); } - if(args["--cors"]){ - response.setHeader("Access-Control-Allow-Origin", "*"); + if (args['--cors']) { + response.setHeader('Access-Control-Allow-Origin', '*'); } - + return handler(request, response, config); }); From 53fc5f9fa59fd4aeb707ab3cddbca3cc91ca0a9f Mon Sep 17 00:00:00 2001 From: Trevor Baron Date: Sun, 5 May 2019 17:45:40 -0700 Subject: [PATCH 3/4] move above compress handler --- bin/serve.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bin/serve.js b/bin/serve.js index 331455fc..4a43444b 100755 --- a/bin/serve.js +++ b/bin/serve.js @@ -173,13 +173,14 @@ const startEndpoint = (endpoint, config, args, previous) => { const compress = args['--no-compression'] !== true; const server = http.createServer(async (request, response) => { - if (compress) { - await compressionHandler(request, response); - } if (args['--cors']) { response.setHeader('Access-Control-Allow-Origin', '*'); } + if (compress) { + await compressionHandler(request, response); + } + return handler(request, response, config); }); From b2148b80cdf73476b3c4c97589afc37ddedae140 Mon Sep 17 00:00:00 2001 From: Trevor Baron Date: Thu, 26 Dec 2019 22:43:36 -0800 Subject: [PATCH 4/4] Update serve.js --- bin/serve.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/serve.js b/bin/serve.js index 3668ee20..daceb964 100755 --- a/bin/serve.js +++ b/bin/serve.js @@ -184,7 +184,7 @@ const startEndpoint = (endpoint, config, args, previous) => { const httpMode = args['--ssl-cert'] && args['--ssl-key'] ? 'https' : 'http'; const serverHandler = async (request, response) => { - if (args['--cors']) { + if (args['--cors']) { response.setHeader('Access-Control-Allow-Origin', '*'); } if (compress) {