mirror of
https://github.com/velocitatem/PHANTOM.git
synced 2026-05-31 08:33:36 +00:00
feat: context switching of hotel/airline depndent on env var via middleware
This commit is contained in:
4
web/src/app/airline/layout.tsx
Normal file
4
web/src/app/airline/layout.tsx
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import { ReactNode } from 'react';
|
||||||
|
export default function AirlineLayout({ children }: { children: ReactNode }) {
|
||||||
|
return <>{children}</>;
|
||||||
|
}
|
||||||
7
web/src/app/airline/page.tsx
Normal file
7
web/src/app/airline/page.tsx
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
export default function AirlineHome() {
|
||||||
|
return (
|
||||||
|
<div className="flex min-h-screen items-center justify-center">
|
||||||
|
<h1 className="text-3xl font-bold">Airline Mode</h1>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
4
web/src/app/hotel/layout.tsx
Normal file
4
web/src/app/hotel/layout.tsx
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import { ReactNode } from 'react';
|
||||||
|
export default function HotelLayout({ children }: { children: ReactNode }) {
|
||||||
|
return <>{children}</>;
|
||||||
|
}
|
||||||
7
web/src/app/hotel/page.tsx
Normal file
7
web/src/app/hotel/page.tsx
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
export default function HotelHome() {
|
||||||
|
return (
|
||||||
|
<div className="flex min-h-screen items-center justify-center">
|
||||||
|
<h1 className="text-3xl font-bold">Hotel Mode</h1>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
35
web/src/middleware.ts
Normal file
35
web/src/middleware.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import { NextRequest, NextResponse } from 'next/server';
|
||||||
|
|
||||||
|
export function middleware(req: NextRequest) {
|
||||||
|
const mode = process.env.STORE_MODE;
|
||||||
|
const { pathname } = req.nextUrl;
|
||||||
|
|
||||||
|
// skip rewrites for api routes, static files, and next internals
|
||||||
|
if (
|
||||||
|
pathname.startsWith('/api') ||
|
||||||
|
pathname.startsWith('/_next') ||
|
||||||
|
pathname.startsWith('/static') ||
|
||||||
|
pathname.includes('.')
|
||||||
|
// TODO: add robots.txt and sitemap.xml if needed here
|
||||||
|
) {
|
||||||
|
return NextResponse.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
// already prefixed with mode
|
||||||
|
if (pathname.startsWith(`/${mode}`)) {
|
||||||
|
return NextResponse.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
// rewrite root and unprefixed paths to mode-specific route group
|
||||||
|
const url = req.nextUrl.clone();
|
||||||
|
url.pathname = `/${mode}${pathname === '/' ? '' : pathname}`;
|
||||||
|
|
||||||
|
return NextResponse.rewrite(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const config = {
|
||||||
|
matcher: [
|
||||||
|
// match all paths except those starting with _next/static, _next/image, favicon.ico
|
||||||
|
'/((?!_next/static|_next/image|favicon.ico).*)',
|
||||||
|
],
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user