Skip to content

Commit

Permalink
feat: add manual routing
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin-Frost committed Oct 12, 2024
1 parent faa65db commit 458bb44
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 38 deletions.
1 change: 1 addition & 0 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default defineConfig({
i18n: {
defaultLocale: defaultLang,
locales: Object.keys(languages),
routing: "manual", // see: src/middleware.ts
},
integrations: [tailwind(), react(), icon()],
site: "https://blz-it.de",
Expand Down
23 changes: 23 additions & 0 deletions src/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { defineMiddleware } from "astro:middleware";
import { defaultLang, languages } from "./i18n";

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

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

const response = await next();

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

return response;
});
32 changes: 0 additions & 32 deletions src/pages/404.astro

This file was deleted.

File renamed without changes.
5 changes: 0 additions & 5 deletions src/pages/index.astro

This file was deleted.

1 change: 0 additions & 1 deletion src/pages/youtube.astro

This file was deleted.

0 comments on commit 458bb44

Please sign in to comment.