mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-17 12:56:05 +00:00
public commit
This commit is contained in:
25
app/src/adapter/nextjs/nextjs.adapter.ts
Normal file
25
app/src/adapter/nextjs/nextjs.adapter.ts
Normal 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);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user