Skip to content

Commit e8fac08

Browse files
committed
Add a thing to force a trailing slash for redirect evaluation
1 parent 815145b commit e8fac08

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

worker/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@ export default class extends WorkerEntrypoint<Env> {
3131
console.error("Could not evaluate redirects", error);
3232
}
3333

34+
try {
35+
const forceTrailingSlashURL = new URL(
36+
request.url.replace(/([^/])$/, "$1/"),
37+
request.url,
38+
);
39+
const redirect = await redirectsEvaluator(
40+
new Request(forceTrailingSlashURL, request),
41+
this.env.ASSETS,
42+
);
43+
if (redirect) {
44+
return redirect;
45+
}
46+
} catch (error) {
47+
console.error("Could not evaluate redirects", error);
48+
}
49+
3450
try {
3551
return await functions.fetch(request, this.env, this.ctx);
3652
} catch (error) {

0 commit comments

Comments
 (0)