fix admin controller to only serve if defined, and only from specified endpoints

This commit is contained in:
dswbx
2025-06-12 09:45:14 +02:00
parent c75f8d0937
commit 4162b9878a
3 changed files with 14 additions and 18 deletions

View File

@@ -1,24 +1,17 @@
import { serveStatic } from "@hono/node-server/serve-static";
import {
type DevServerOptions,
default as honoViteDevServer,
} from "@hono/vite-dev-server";
import { type DevServerOptions, default as honoViteDevServer } from "@hono/vite-dev-server";
import type { App } from "bknd";
import {
type RuntimeBkndConfig,
createRuntimeApp,
type FrameworkOptions,
} from "bknd/adapter";
import { type RuntimeBkndConfig, createRuntimeApp, type FrameworkOptions } from "bknd/adapter";
import { registerLocalMediaAdapter } from "bknd/adapter/node";
import { devServerConfig } from "./dev-server-config";
import type { MiddlewareHandler } from "hono";
export type ViteEnv = NodeJS.ProcessEnv;
export type ViteBkndConfig<Env = ViteEnv> = RuntimeBkndConfig<Env> & {};
export type ViteBkndConfig<Env = ViteEnv> = RuntimeBkndConfig<Env> & {
serveStatic?: false | MiddlewareHandler;
};
export function addViteScript(
html: string,
addBkndContext: boolean = true,
) {
export function addViteScript(html: string, addBkndContext: boolean = true) {
return html.replace(
"</head>",
`<script type="module">
@@ -48,7 +41,10 @@ async function createApp<ViteEnv>(
mainPath: "/src/main.tsx",
},
},
serveStatic: ["/assets/*", serveStatic({ root: config.distPath ?? "./" })],
serveStatic: config.serveStatic || [
"/assets/*",
serveStatic({ root: config.distPath ?? "./" }),
],
},
env,
opts,

View File

@@ -50,7 +50,7 @@ export class AdminController extends Controller {
}
get basepath() {
return this.options.basepath ?? "/";
return this.withAdminBasePath();
}
private withBasePath(route: string = "") {