34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
|
|
import type { Handle } from '@sveltejs/kit';
|
||
|
|
|
||
|
|
const ADMIN_HOSTNAME = 'admin.goodwalk.co.nz';
|
||
|
|
const ADMIN_PATH = '/owner/welcome';
|
||
|
|
|
||
|
|
function isAdminHost(hostname: string | undefined | null): boolean {
|
||
|
|
if (!hostname) return false;
|
||
|
|
return hostname.toLowerCase() === ADMIN_HOSTNAME;
|
||
|
|
}
|
||
|
|
|
||
|
|
export const handle: Handle = async ({ event, resolve }) => {
|
||
|
|
const onAdminHost = isAdminHost(event.url.hostname);
|
||
|
|
const path = event.url.pathname;
|
||
|
|
|
||
|
|
// The admin host serves the dashboard at its root.
|
||
|
|
if (onAdminHost && (path === '/' || path === '')) {
|
||
|
|
return new Response(null, {
|
||
|
|
status: 302,
|
||
|
|
headers: { location: ADMIN_PATH },
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
// Block the admin dashboard from the public marketing host so it only
|
||
|
|
// lives on admin.goodwalk.co.nz in production. Localhost and the
|
||
|
|
// onboarding subdomain are still allowed for development and migration.
|
||
|
|
const hostname = event.url.hostname.toLowerCase();
|
||
|
|
const isPublicMarketingHost = hostname === 'goodwalk.co.nz' || hostname === 'www.goodwalk.co.nz';
|
||
|
|
if (isPublicMarketingHost && path.startsWith('/owner/')) {
|
||
|
|
return new Response('Not Found', { status: 404 });
|
||
|
|
}
|
||
|
|
|
||
|
|
return resolve(event);
|
||
|
|
};
|