mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 12:37:20 +00:00
Refactor asset handling and authentication logic (for node)
Updated asset path configuration and server-side logic to standardize asset serving. Introduced `shouldSkipAuth` to bypass authentication for asset requests. Added test coverage for the new asset path handling logic.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/** @jsxImportSource hono/jsx */
|
||||
|
||||
import type { App } from "App";
|
||||
import { isDebug } from "core";
|
||||
import { config, isDebug } from "core";
|
||||
import { addFlashMessage } from "core/server/flash";
|
||||
import { html } from "hono/html";
|
||||
import { Fragment } from "hono/jsx";
|
||||
@@ -13,6 +13,7 @@ const htmlBkndContextReplace = "<!-- BKND_CONTEXT -->";
|
||||
// @todo: add migration to remove admin path from config
|
||||
export type AdminControllerOptions = {
|
||||
basepath?: string;
|
||||
assets_path?: string;
|
||||
html?: string;
|
||||
forceDev?: boolean | { mainPath: string };
|
||||
};
|
||||
@@ -20,7 +21,7 @@ export type AdminControllerOptions = {
|
||||
export class AdminController extends Controller {
|
||||
constructor(
|
||||
private readonly app: App,
|
||||
private options: AdminControllerOptions = {}
|
||||
private _options: AdminControllerOptions = {}
|
||||
) {
|
||||
super();
|
||||
}
|
||||
@@ -29,6 +30,14 @@ export class AdminController extends Controller {
|
||||
return this.app.modules.ctx();
|
||||
}
|
||||
|
||||
get options() {
|
||||
return {
|
||||
...this._options,
|
||||
basepath: this._options.basepath ?? "/",
|
||||
assets_path: this._options.assets_path ?? config.server.assets_path
|
||||
};
|
||||
}
|
||||
|
||||
get basepath() {
|
||||
return this.options.basepath ?? "/";
|
||||
}
|
||||
@@ -156,8 +165,16 @@ export class AdminController extends Controller {
|
||||
<title>BKND</title>
|
||||
{isProd ? (
|
||||
<Fragment>
|
||||
<script type="module" CrossOrigin src={"/" + assets?.js} />
|
||||
<link rel="stylesheet" crossOrigin href={"/" + assets?.css} />
|
||||
<script
|
||||
type="module"
|
||||
CrossOrigin
|
||||
src={this.options.assets_path + assets?.js}
|
||||
/>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
crossOrigin
|
||||
href={this.options.assets_path + assets?.css}
|
||||
/>
|
||||
</Fragment>
|
||||
) : (
|
||||
<Fragment>
|
||||
|
||||
Reference in New Issue
Block a user