From 89089346534f24adabf239317911ef6d1c14f4ea Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Sun, 12 Nov 2023 15:51:06 +0800 Subject: fix: dynamically get base for absolute URLs --- src/env.ts | 1 - src/index.ts | 8 +++----- 2 files changed, 3 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/env.ts b/src/env.ts index a39f506..01b9713 100644 --- a/src/env.ts +++ b/src/env.ts @@ -1,6 +1,5 @@ export type Bindings = { ASSETS: Fetcher; - URL?: string; REDIRECT_ROOT?: string; }; diff --git a/src/index.ts b/src/index.ts index 397dd30..3126b15 100644 --- a/src/index.ts +++ b/src/index.ts @@ -26,7 +26,7 @@ app.get("/list_teawies", zValidator("query", list), async (c) => { return c.json( WIES.slice(0, parseInt(limit ?? "5")).map((wie) => { return { - url: `${c.env.URL ?? "https://api.mydadleft.me"}/${WIE_DIR}/${wie}`, + url: new URL(`/${WIE_DIR}/${wie}`, c.req.url).toString(), }; }), ); @@ -36,12 +36,10 @@ app.get("/random_teawie", (c) => { const wie = WIES[Math.floor(Math.random() * WIES.length)]; return c.json({ - url: `${c.env.URL ?? "https://api.mydadleft.me"}/${WIE_DIR}/${wie}`, + url: new URL(`/${WIE_DIR}/${wie}`, c.req.url).toString(), }); }); -app.get("/get_random_teawie", (c) => { - return c.redirect(`${c.env.URL ?? "https://api.mydadleft.me"}/random_teawie`); -}); +app.get("/get_random_teawie", (c) => c.redirect("/random_teawie")); export default app; -- cgit v1.2.3