public commit

This commit is contained in:
dswbx
2024-11-16 12:01:47 +01:00
commit 90f80c4280
582 changed files with 49291 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
import { App, type CreateAppConfig } from "bknd";
import { isDebug } from "bknd/core";
function getCleanRequest(req: Request) {
// clean search params from "route" attribute
const url = new URL(req.url);
url.searchParams.delete("route");
return new Request(url.toString(), {
method: req.method,
headers: req.headers,
body: req.body
});
}
let app: App;
export function serve(config: CreateAppConfig) {
return async (req: Request) => {
if (!app || isDebug()) {
app = App.create(config);
await app.build();
}
const request = getCleanRequest(req);
return app.fetch(request, process.env);
};
}