diff --git a/.gitignore b/.gitignore index 0218897..ae79ae0 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,5 @@ dist/*.js changelog.json changelog_latest.json .DS_Store -wrangler.toml .env +/wrangler.toml \ No newline at end of file diff --git a/src/js/pricing/worker.js b/src/js/pricing/worker.js new file mode 100644 index 0000000..08621fe --- /dev/null +++ b/src/js/pricing/worker.js @@ -0,0 +1,22 @@ +export default { + async fetch(request) { + const urlObject = new URL(request.url); + + urlObject.hostname = 'webflow.bitrise.io'; + + if (urlObject.search.match(/us=1/) || request.headers.get('cf-ipcountry') === 'US') { + urlObject.pathname = '/plans-pricing-us'; + const response = await fetch(urlObject); + const data = (await response.text()).replace('plans-pricing-us', 'plans-pricing'); + return new Response(data, { + status: response.status, + statusText: response.statusText, + headers: Object.fromEntries(response.headers.entries()), + }); + } + + urlObject.pathname = urlObject.pathname.replace('plans-pricing-test', 'plans-pricing'); + + return fetch(urlObject); + }, +}; diff --git a/src/js/pricing/wrangler.toml b/src/js/pricing/wrangler.toml new file mode 100644 index 0000000..8e68b1e --- /dev/null +++ b/src/js/pricing/wrangler.toml @@ -0,0 +1,5 @@ +name = "pricing-proxy" +main = "./src/js/pricing/worker.js" +compatibility_date = "2023-08-23" +route = "bitrise.io/plans-pricing-test*" +no_bundle = true \ No newline at end of file