fixed nextjs build + confirmed node adapter

This commit is contained in:
dswbx
2024-11-27 17:07:56 +01:00
parent c31bc2ccb0
commit b6e3c934c4
5 changed files with 19 additions and 19 deletions

View File

@@ -173,3 +173,9 @@ await tsup.build({
await tsup.build({
...baseConfig("bun")
});
await tsup.build({
...baseConfig("node"),
platform: "node",
format: ["esm", "cjs"]
});

View File

@@ -1,6 +1,5 @@
import type { IncomingMessage, ServerResponse } from "node:http";
import { Api, App, type CreateAppConfig } from "bknd";
import { isDebug } from "bknd/core";
import { nodeRequestToRequest } from "../index";
type GetServerSidePropsContext = {
@@ -46,7 +45,7 @@ function getCleanRequest(req: Request) {
let app: App;
export function serve(config: CreateAppConfig) {
return async (req: Request) => {
if (!app || isDebug()) {
if (!app) {
app = App.create(config);
await app.build();
}

View File

@@ -1,10 +1,8 @@
import { readFile } from "node:fs/promises";
import path from "node:path";
import { serve as honoServe } from "@hono/node-server";
import { serveStatic } from "@hono/node-server/serve-static";
import { App, type CreateAppConfig } from "bknd";
import { LibsqlConnection } from "bknd/data";
import type { Manifest } from "vite";
async function getConnection(conn?: CreateAppConfig["connection"]) {
if (conn) {
@@ -26,7 +24,6 @@ async function getConnection(conn?: CreateAppConfig["connection"]) {
export type NodeAdapterOptions = {
relativeDistPath?: string;
viteManifest?: Manifest;
port?: number;
hostname?: string;
listener?: Parameters<typeof honoServe>[1];
@@ -51,22 +48,16 @@ export function serve(_config: Partial<CreateAppConfig> = {}, options: NodeAdapt
connection
});
const viteManifest =
options.viteManifest ??
JSON.parse(await readFile(path.resolve(root, ".vite/manifest.json"), "utf-8"));
app.emgr.on(
"app-built",
async () => {
app.modules.server.get(
"/assets/*",
"/*",
serveStatic({
root
})
);
app.registerAdminController({
viteManifest
});
app.registerAdminController();
},
"sync"
);

View File

@@ -12,10 +12,10 @@ Install bknd as a dependency:
``` tsx
// pages/api/[...route].ts
import { serve } from "bknd/adapter/nextjs";
import type { PageConfig } from "next";
export const config: PageConfig = {
runtime: "edge"
export const config = {
runtime: "experimental-edge",
unstable_allowDynamic: ["**/*.js"]
};
export default serve({

View File

@@ -1,8 +1,12 @@
import { serve } from "bknd/adapter/nextjs";
import type { PageConfig } from "next";
export const config: PageConfig = {
runtime: "edge"
export const config = {
runtime: "experimental-edge",
// add a matcher for bknd dist to allow dynamic otherwise build may fail.
// inside this repo it's '../../app/dist/index.js', outside probably inside node_modules
// see https://github.com/vercel/next.js/issues/51401
// and https://github.com/vercel/next.js/pull/69402
unstable_allowDynamic: ["**/*.js"]
};
export default serve({