From 5c7069049dcd72368de663a7cd105b6342e8d27f Mon Sep 17 00:00:00 2001 From: Yangshun Date: Tue, 17 Sep 2024 20:06:14 +0800 Subject: [PATCH] web: add function to redirect Grind 75 path --- apps/website/.gitignore | 5 ++++- apps/website/functions/grind75/[[catchall]].js | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 apps/website/functions/grind75/[[catchall]].js diff --git a/apps/website/.gitignore b/apps/website/.gitignore index 1b34df51..b0f9427a 100755 --- a/apps/website/.gitignore +++ b/apps/website/.gitignore @@ -17,4 +17,7 @@ npm-debug.log* yarn-debug.log* -yarn-error.log* \ No newline at end of file +yarn-error.log* + +# cloudflare +.wrangler diff --git a/apps/website/functions/grind75/[[catchall]].js b/apps/website/functions/grind75/[[catchall]].js new file mode 100644 index 00000000..fb0b32ce --- /dev/null +++ b/apps/website/functions/grind75/[[catchall]].js @@ -0,0 +1,13 @@ +const SOURCE_HOST = 'https://grind75.vercel.app'; + +export async function onRequest(context) { + const { request } = context; + // Define the original and target paths + const url = new URL(request.url); + + // Rewrite to the new domain, preserving the original path and query string + const newURL = SOURCE_HOST + url.pathname + url.search; + + // Fetch the content from the new domain + return await fetch(newURL, request); +}