Skip to content

Commit

Permalink
fix: middleware not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin-Frost committed Oct 14, 2024
1 parent bc8a95d commit f9f088b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@ import { defaultLang, languages } from "./i18n";

export const onRequest = defineMiddleware(async (ctx, next) => {
if (ctx.url.pathname === "/youtube") {
return Response.redirect("https://youtube.de/@GermanITSkills");
return Response.redirect("https://youtube.de/@GermanITSkills", 301);
}

if (ctx.url.pathname.startsWith("/_image")) {
return next();
}

const [, lang] = ctx.url.pathname.split("/");
if (!(lang in languages)) {
return Response.redirect(
new URL(`/${defaultLang}${ctx.url.pathname}`, ctx.url),
301,
);
}

const response = await next();

if (response.status === 404) {
return Response.redirect(new URL(`/${lang}/not-found`, ctx.url));
return next(new URL(`/${lang}/404`, ctx.url));
}

return response;
Expand Down
File renamed without changes.
Empty file added src/pages/index.astro
Empty file.

0 comments on commit f9f088b

Please sign in to comment.