From 55006e41e8e656707a6bec11d682427879b1b1bd Mon Sep 17 00:00:00 2001 From: Antal Orcsik Date: Thu, 27 Jun 2024 15:18:18 +0200 Subject: [PATCH] pricing A/B test worker --- .gitignore | 2 +- src/js/pricing/worker.js | 22 ++++++++++++++++++++++ src/js/pricing/wrangler.toml | 5 +++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/js/pricing/worker.js create mode 100644 src/js/pricing/wrangler.toml 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