revert: undo adminPath routing attempts — clean slate for restart
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
import { loadConfig } from '$lib/server/data';
|
||||
import type { Handle } from '@sveltejs/kit';
|
||||
|
||||
/**
|
||||
* handle: no URL rewriting here (that's reroute in hooks.ts).
|
||||
* Kept as a placeholder for future server-only middleware.
|
||||
*/
|
||||
export const handle: Handle = async ({ event, resolve }) => {
|
||||
return resolve(event);
|
||||
};
|
||||
40
src/hooks.ts
40
src/hooks.ts
@@ -1,40 +0,0 @@
|
||||
import type { Reroute } from '@sveltejs/kit';
|
||||
|
||||
/**
|
||||
* reroute: rewrites the configured adminPath to the internal /admin route.
|
||||
* Reads config.json directly (not via $lib/server/data) so this universal
|
||||
* hook can run server-side without triggering the browser-import guard.
|
||||
*
|
||||
* Example: adminPath = "boss"
|
||||
* /boss → /admin
|
||||
* /boss/login → /admin/login
|
||||
* /boss/api/... → /admin/api/...
|
||||
*/
|
||||
export const reroute: Reroute = ({ url }) => {
|
||||
// Only runs on the server — typeof window is undefined here during SSR/Node.
|
||||
// In the browser, SvelteKit client-side routing never calls reroute for
|
||||
// server routes, so this branch is safe to guard.
|
||||
if (typeof window !== 'undefined') return url.pathname;
|
||||
|
||||
try {
|
||||
// Dynamic require so bundler doesn't try to resolve at build time
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
const fs = require('fs') as typeof import('fs');
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
const path = require('path') as typeof import('path');
|
||||
const configPath = path.resolve('data', 'config.json');
|
||||
const config = JSON.parse(fs.readFileSync(configPath, 'utf8')) as { adminPath?: string };
|
||||
const adminPath = (config.adminPath ?? 'admin').replace(/^\/|\/$/g, '');
|
||||
|
||||
if (adminPath === 'admin') return url.pathname;
|
||||
|
||||
const prefix = `/${adminPath}`;
|
||||
if (url.pathname === prefix || url.pathname.startsWith(prefix + '/')) {
|
||||
return '/admin' + url.pathname.slice(prefix.length);
|
||||
}
|
||||
} catch {
|
||||
// If config can't be read, fall through to default routing
|
||||
}
|
||||
|
||||
return url.pathname;
|
||||
};
|
||||
@@ -1,6 +1,5 @@
|
||||
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 }) => {
|
||||
@@ -15,9 +14,7 @@ export const load: LayoutServerLoad = ({ request, url }) => {
|
||||
}
|
||||
|
||||
if (!authRequest(request)) {
|
||||
// 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`);
|
||||
throw redirect(302, '/admin/login');
|
||||
}
|
||||
|
||||
return { authenticated: true };
|
||||
|
||||
@@ -771,8 +771,6 @@
|
||||
>
|
||||
<span
|
||||
class="drag-handle"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
draggable="true"
|
||||
ondragstart={(e) => onUnitDragStart(e, unit.id, null)}
|
||||
ondragend={onUnitDragEnd}
|
||||
|
||||
Reference in New Issue
Block a user