diff --git a/data/.config.json.swp b/data/.config.json.swp new file mode 100644 index 0000000..886da71 Binary files /dev/null and b/data/.config.json.swp differ diff --git a/data/units.json b/data/units.json index 554be37..d03b109 100644 --- a/data/units.json +++ b/data/units.json @@ -71,6 +71,22 @@ "symbol": "mfcktn", "group": "dickloads", "toBase": 170.2399999998 + }, + { + "id": "shitload", + "label": "Shitload", + "labelPlural": "Shitloads", + "symbol": "shtld", + "group": "dickloads", + "toBase": 12.6666666667 + }, + { + "id": "shit-ton", + "label": "Shit ton", + "labelPlural": "Shit tons", + "symbol": "shttn", + "group": "dickloads", + "toBase": 25.3333333333 } ], "groups": [ diff --git a/src/hooks.server.ts b/src/hooks.server.ts new file mode 100644 index 0000000..756fe1e --- /dev/null +++ b/src/hooks.server.ts @@ -0,0 +1,36 @@ +import { loadConfig } from '$lib/server/data'; +import type { Handle } from '@sveltejs/kit'; + +/** + * Rewrites requests from the configured adminPath to the internal /admin route. + * + * Example: if adminPath = "secret-panel", then: + * /secret-panel → /admin + * /secret-panel/login → /admin/login + * /secret-panel/api/units → /admin/api/units + * + * If adminPath = "admin" (default), this is a no-op. + */ +export const handle: Handle = async ({ event, resolve }) => { + const config = loadConfig(); + const adminPath = (config.adminPath ?? 'admin').replace(/^\/|\/$/g, ''); + + if (adminPath !== 'admin') { + const url = event.url; + const prefix = `/${adminPath}`; + + if (url.pathname === prefix || url.pathname.startsWith(prefix + '/')) { + // Rewrite the URL to use /admin internally + const rewritten = '/admin' + url.pathname.slice(prefix.length); + event.url = new URL(rewritten + url.search + url.hash, url.origin); + // Also update request.url so auth helpers see the rewritten path + Object.defineProperty(event.request, 'url', { + value: event.url.toString(), + writable: false, + configurable: true + }); + } + } + + return resolve(event); +}; diff --git a/src/routes/admin/+layout.server.ts b/src/routes/admin/+layout.server.ts index bfb46d4..cb62807 100644 --- a/src/routes/admin/+layout.server.ts +++ b/src/routes/admin/+layout.server.ts @@ -1,5 +1,6 @@ import { redirect } from '@sveltejs/kit'; import { authRequest } from '$lib/server/auth'; +import { loadConfig } from '$lib/server/data'; import type { LayoutServerLoad } from './$types'; export const load: LayoutServerLoad = ({ request, url }) => { @@ -14,7 +15,9 @@ export const load: LayoutServerLoad = ({ request, url }) => { } if (!authRequest(request)) { - throw redirect(302, '/admin/login'); + // Redirect to login using the configured admin path so the URL stays consistent + const adminPath = (loadConfig().adminPath ?? 'admin').replace(/^\/|\/$/g, ''); + throw redirect(302, `/${adminPath}/login`); } return { authenticated: true };