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

View File

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

View File

@@ -5,6 +5,6 @@ import react from "@astrojs/react";
// https://astro.build/config // https://astro.build/config
export default defineConfig({ export default defineConfig({
output: "hybrid", output: "server",
integrations: [react()] integrations: [react()],
}); });