mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
public commit
This commit is contained in:
33
app/src/adapter/bun/bun.adapter.ts
Normal file
33
app/src/adapter/bun/bun.adapter.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { readFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { App, type CreateAppConfig } from "bknd";
|
||||
import { serveStatic } from "hono/bun";
|
||||
|
||||
let app: App;
|
||||
export function serve(config: CreateAppConfig, distPath?: string) {
|
||||
const root = path.resolve(distPath ?? "./node_modules/bknd/dist", "static");
|
||||
|
||||
return async (req: Request) => {
|
||||
if (!app) {
|
||||
app = App.create(config);
|
||||
|
||||
app.emgr.on(
|
||||
"app-built",
|
||||
async () => {
|
||||
app.modules.server.get(
|
||||
"/assets/*",
|
||||
serveStatic({
|
||||
root
|
||||
})
|
||||
);
|
||||
app.module?.server?.setAdminHtml(await readFile(root + "/index.html", "utf-8"));
|
||||
},
|
||||
"sync"
|
||||
);
|
||||
|
||||
await app.build();
|
||||
}
|
||||
|
||||
return app.modules.server.fetch(req);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user