Redirect automatically if the site isnt running on the correct url
Signed-off-by: baalajimaestro <me@baalajimaestro.me>
This commit is contained in:
parent
7a4335a986
commit
52c22d7fb0
2 changed files with 19 additions and 0 deletions
18
src/middleware.ts
Normal file
18
src/middleware.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { defineMiddleware } from "astro:middleware";
|
||||
import siteConfig from "./site-config";
|
||||
|
||||
export const onRequest = defineMiddleware((context, next) => {
|
||||
const { url, request } = context;
|
||||
|
||||
if (import.meta.env.PROD) {
|
||||
const configuredUrl = new URL(siteConfig.siteUrl);
|
||||
|
||||
if (url.hostname !== configuredUrl.hostname) {
|
||||
const newUrl = new URL(url.pathname + url.search, configuredUrl);
|
||||
|
||||
return Response.redirect(newUrl.toString(), 301);
|
||||
}
|
||||
}
|
||||
|
||||
return next();
|
||||
});
|
|
@ -4,6 +4,7 @@ export const siteConfig = {
|
|||
subtitle: 'DevOps Engineer and Networking Enthusiast.',
|
||||
description: 'Personal Website & Blog for baalajimaestro',
|
||||
email: 'baalajimaestro@ptr.moe',
|
||||
siteUrl: 'https://baalajimaestro.ptr.moe',
|
||||
header: {
|
||||
logo: {
|
||||
src: '/images/favicon.png',
|
||||
|
|
Loading…
Reference in a new issue