From 3f6a3229c3cc7af7667530b43f5997314a769a9f Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Thu, 3 Nov 2022 00:33:48 -0700 Subject: [PATCH] Prepend protocol if none is given --- cors/index.js | 2 +- cors/wrangler.toml.example | 2 +- proxy/index.js | 2 +- proxy/wrangler.toml.example | 2 +- style/index.js | 2 +- style/wrangler.toml.example | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cors/index.js b/cors/index.js index 454bede..6280041 100644 --- a/cors/index.js +++ b/cors/index.js @@ -1,6 +1,6 @@ export default { async fetch(request) { - const url = new URL(request.url); + const url = /^http(s)?:\/\//i.test(request.url) ? new URL(request.url) : new URL(`https://${request.url}`); const queryString = decodeURIComponent(url.search.substring(1)); let response; diff --git a/cors/wrangler.toml.example b/cors/wrangler.toml.example index 2c0143a..a9d818f 100644 --- a/cors/wrangler.toml.example +++ b/cors/wrangler.toml.example @@ -1,4 +1,4 @@ name = 'cors' main = 'index.js' -compatibility_date = '2022-07-10' +compatibility_date = '2022-11-03' route = 'example.com/*' diff --git a/proxy/index.js b/proxy/index.js index 2eb7f8d..8e87678 100644 --- a/proxy/index.js +++ b/proxy/index.js @@ -1,6 +1,6 @@ export default { async fetch(request) { - const url = new URL(request.url); + const url = /^http(s)?:\/\//i.test(request.url) ? new URL(request.url) : new URL(`https://${request.url}`); const queryString = decodeURIComponent(url.search.substring(1)); return await fetch(queryString); } diff --git a/proxy/wrangler.toml.example b/proxy/wrangler.toml.example index d45cc19..e3cdc64 100644 --- a/proxy/wrangler.toml.example +++ b/proxy/wrangler.toml.example @@ -1,4 +1,4 @@ name = 'proxy' main = 'index.js' -compatibility_date = '2022-07-10' +compatibility_date = '2022-11-03' route = 'example.com/*' diff --git a/style/index.js b/style/index.js index 5638019..9874c4d 100644 --- a/style/index.js +++ b/style/index.js @@ -6,7 +6,7 @@ class InjectStyle { export default { async fetch(request) { - const url = new URL(request.url); + const url = /^http(s)?:\/\//i.test(request.url) ? new URL(request.url) : new URL(`https://${request.url}`); const queryString = decodeURIComponent(url.search.substring(1)); const response = await fetch(queryString); diff --git a/style/wrangler.toml.example b/style/wrangler.toml.example index 8607183..5a4d56a 100644 --- a/style/wrangler.toml.example +++ b/style/wrangler.toml.example @@ -1,4 +1,4 @@ name = 'style' main = 'index.js' -compatibility_date = '2022-07-10' +compatibility_date = '2022-11-03' route = 'example.com/*' -- 2.47.3