This commit is contained in:
2026-05-19 23:36:58 +12:00
parent 5172588488
commit a7f8a619b1
68 changed files with 4486 additions and 1430 deletions
+10 -15
View File
@@ -1,31 +1,26 @@
import type { Handle } from '@sveltejs/kit';
import { resolveSurface } from '$lib/server/surface';
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 { surface } = resolveSurface(event.url, event.cookies);
const path = event.url.pathname;
// The admin host serves the dashboard at its root.
if (onAdminHost && (path === '/' || path === '')) {
// The admin host (cp.*) serves the dashboard at its root.
if (surface === 'cp' && (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/')) {
// Block the admin dashboard from the public marketing site so /owner/*
// only renders on the cp surface (or on the clients surface during the
// legacy onboarding-host transition window). Localhost dev preview is
// allowed: resolveSurface returns 'cp' there too when ?preview=cp or
// ?preview=admin is set.
if (surface === 'marketing' && path.startsWith('/owner/')) {
return new Response('Not Found', { status: 404 });
}