Files
sweet/www/routes/docs/_middleware.ts
T
Marvin Hagemeister 240252fdb4 Revert "feat: add ctx.redirect() helper (#2358)" (#2372)
Mostly so that it's easier to cut the next patch release for Fresh.

This reverts commit e3508c3054.
2024-03-21 10:27:53 +01:00

24 lines
548 B
TypeScript

import { FreshContext } from "$fresh/server.ts";
const REDIRECTS: Record<string, string> = {
"/docs/getting-started/fetching-data":
"/docs/getting-started/custom-handlers",
};
export async function handler(
_req: Request,
ctx: FreshContext,
) {
// Redirect from old doc URLs to new ones
const redirect = REDIRECTS[ctx.url.pathname];
if (redirect) {
const url = new URL(redirect, ctx.url.origin);
return new Response("", {
status: 307,
headers: { location: url.href },
});
}
return await ctx.next();
}