summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRyan Cao <[email protected]>2023-11-12 15:51:06 +0800
committerseth <[email protected]>2023-11-12 08:01:14 +0000
commit89089346534f24adabf239317911ef6d1c14f4ea (patch)
tree7d03d19dd87067574b2bd8677f126d1c2185be2b /src
parent66a32af19878f8fc341c4e74b9324ea3e7c90b84 (diff)
fix: dynamically get base for absolute URLs
Diffstat (limited to 'src')
-rw-r--r--src/env.ts1
-rw-r--r--src/index.ts8
2 files changed, 3 insertions, 6 deletions
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;