diff options
| author | Alex Pooley (@zuedev) <zuedev@gmail.com> | 2025-12-19 13:48:12 +0000 |
|---|---|---|
| committer | Alex Pooley (@zuedev) <zuedev@gmail.com> | 2025-12-19 13:48:12 +0000 |
| commit | b9d42d5c6102800688c08cd77de18b1b40255ba7 (patch) | |
| tree | ea552d9db545e8a71bfdc7e23c31c57a8ad58b4c /server/index.js | |
| parent | 5728d4bec0ac5225fcdc23b1b936960010177242 (diff) | |
| download | zue.dev-b9d42d5c6102800688c08cd77de18b1b40255ba7.tar zue.dev-b9d42d5c6102800688c08cd77de18b1b40255ba7.tar.gz zue.dev-b9d42d5c6102800688c08cd77de18b1b40255ba7.tar.bz2 zue.dev-b9d42d5c6102800688c08cd77de18b1b40255ba7.tar.xz zue.dev-b9d42d5c6102800688c08cd77de18b1b40255ba7.zip | |
Add configuration for rewrites to handle /shadow-vrchat.ps1 requests
Diffstat (limited to 'server/index.js')
| -rw-r--r-- | server/index.js | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/server/index.js b/server/index.js index 57ed1d6..c49529e 100644 --- a/server/index.js +++ b/server/index.js @@ -1,5 +1,16 @@ import puppeteer from "@cloudflare/puppeteer"; +const configuration = { + rewrites: [ + { + domain: "zue.dev", + path: "/shadow-vrchat.ps1", + destination: + "https://raw.githubusercontent.com/zuedev/monorepo/main/unsorted/Shadow%20VRChat%20Devbox/setup.ps1", + }, + ], +}; + export default { /* Fetch event handler, this function will be called whenever a request is made to the worker. @@ -29,16 +40,23 @@ export default { if (url.hostname === "bbg.zue.dev") return Response.redirect(`https://zue.dev/bbg/${url.pathname}`, 301); - if (url.pathname === "/shadow-vrchat.ps1") { - // fetch the script first - const scriptResponse = await fetch( - "https://raw.githubusercontent.com/zuedev/monorepo/main/unsorted/Shadow%20VRChat%20Devbox/setup.ps1" + // Handle rewrites from configuration object + if ( + configuration.rewrites && + configuration.rewrites.length > 0 && + configuration.rewrites.some((r) => r.domain === url.hostname) && + configuration.rewrites.some((r) => r.path === url.pathname) + ) { + const rewrite = configuration.rewrites.find( + (r) => r.domain === url.hostname && r.path === url.pathname ); - // return the script as text/plain - return new Response(scriptResponse.body, { + const fetchResponse = await fetch(rewrite.destination); + + return new Response(fetchResponse.body, { headers: { - "Content-Type": "text/plain", + "Content-Type": + fetchResponse.headers.get("Content-Type") || "text/plain", }, }); } |
