]> git.ardis.lu - cloudflare-workers/commitdiff
Prepend protocol if none is given
authorArdis Lu <ardisglu@gmail.com>
Thu, 3 Nov 2022 07:33:48 +0000 (00:33 -0700)
committerArdis Lu <ardisglu@gmail.com>
Thu, 3 Nov 2022 07:33:48 +0000 (00:33 -0700)
cors/index.js
cors/wrangler.toml.example
proxy/index.js
proxy/wrangler.toml.example
style/index.js
style/wrangler.toml.example

index 454bede8f8143f78d2ec4885fd759480f00d41db..62800415f077b02343588b0a589db73704e150e2 100644 (file)
@@ -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;
index 2c0143aa529d2a11d3c2548ca6e59737ee487e94..a9d818f0036b7ce4867d57f3770264f30c9179c2 100644 (file)
@@ -1,4 +1,4 @@
 name = 'cors'
 main = 'index.js'
-compatibility_date = '2022-07-10'
+compatibility_date = '2022-11-03'
 route = 'example.com/*'
index 2eb7f8dca28a321026d02b3887cf10292a0cdf82..8e876784e419f01887f610e9a1bba9d6ac49652b 100644 (file)
@@ -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);
   }
index d45cc19d2fbccf23c022a4ead50b8ccee2f55ddc..e3cdc647d712c67ea2c45a1a3e560d2fef62e790 100644 (file)
@@ -1,4 +1,4 @@
 name = 'proxy'
 main = 'index.js'
-compatibility_date = '2022-07-10'
+compatibility_date = '2022-11-03'
 route = 'example.com/*'
index 56380196e711dd432f46ab8ca5754009f6992610..9874c4d1f2c371530efd1641e973b387eb425f27 100644 (file)
@@ -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);
index 860718359c860e1a078a7beed4b5a449313caace..5a4d56a97073aacdf28c552df39de0fc6fb63f07 100644 (file)
@@ -1,4 +1,4 @@
 name = 'style'
 main = 'index.js'
-compatibility_date = '2022-07-10'
+compatibility_date = '2022-11-03'
 route = 'example.com/*'
This page took 0.045604 seconds and 4 git commands to generate.