mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
fix admin controller to only serve if defined, and only from specified endpoints
This commit is contained in:
@@ -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,
|
||||||
|
|||||||
@@ -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 = "") {
|
||||||
|
|||||||
@@ -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()],
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user