Skip to content

Commit 49d60ad

Browse files
authored
fix(redirects): use Cloudflare Worker for install script redirects (#10)
1 parent d072f2e commit 49d60ad

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

website/public/_redirects

Lines changed: 0 additions & 2 deletions
This file was deleted.

website/worker.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const REDIRECTS: Record<string, string> = {
2+
'/install.ps1': 'https://github.com/CodingWithCalvin/dtvem.cli/releases/latest/download/install.ps1',
3+
'/install.sh': 'https://github.com/CodingWithCalvin/dtvem.cli/releases/latest/download/install.sh',
4+
};
5+
6+
export default {
7+
async fetch(request: Request, env: { ASSETS: { fetch: typeof fetch } }): Promise<Response> {
8+
const url = new URL(request.url);
9+
10+
// Check for redirects
11+
const redirectTarget = REDIRECTS[url.pathname];
12+
if (redirectTarget) {
13+
return Response.redirect(redirectTarget, 302);
14+
}
15+
16+
// Fall through to static assets
17+
return env.ASSETS.fetch(request);
18+
},
19+
};

website/wrangler.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
name = "dtvem-io"
2+
main = "./worker.ts"
23
compatibility_date = "2024-12-01"
34

45
[assets]

0 commit comments

Comments
 (0)