mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 12:37:20 +00:00
Merge remote-tracking branch 'origin/release/0.9' into feat/app-api-exp-for-nextjs
# Conflicts: # app/src/adapter/nextjs/nextjs.adapter.ts # app/src/index.ts
This commit is contained in:
@@ -17,7 +17,7 @@ export type Options = {
|
||||
export async function getApi(Astro: TAstro, options: Options = { mode: "static" }) {
|
||||
const api = new Api({
|
||||
host: new URL(Astro.request.url).origin,
|
||||
headers: options.mode === "dynamic" ? Astro.request.headers : undefined
|
||||
headers: options.mode === "dynamic" ? Astro.request.headers : undefined,
|
||||
});
|
||||
await api.verifyAuth();
|
||||
return api;
|
||||
|
||||
@@ -19,7 +19,7 @@ export async function createApp({ distPath, ...config }: RuntimeBkndConfig = {})
|
||||
registerLocalMediaAdapter();
|
||||
app = await createRuntimeApp({
|
||||
...config,
|
||||
serveStatic: serveStatic({ root })
|
||||
serveStatic: serveStatic({ root }),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -46,10 +46,10 @@ export function serve({
|
||||
options,
|
||||
onBuilt,
|
||||
buildConfig,
|
||||
distPath
|
||||
distPath,
|
||||
});
|
||||
return app.fetch(request);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
console.log(`Server is running on http://localhost:${port}`);
|
||||
|
||||
@@ -12,7 +12,7 @@ export type D1ConnectionConfig = {
|
||||
class CustomD1Dialect extends D1Dialect {
|
||||
override createIntrospector(db: Kysely<any>): DatabaseIntrospector {
|
||||
return new SqliteIntrospector(db, {
|
||||
excludeTables: ["_cf_KV"]
|
||||
excludeTables: ["_cf_KV"],
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ export class D1Connection extends SqliteConnection {
|
||||
|
||||
const kysely = new Kysely({
|
||||
dialect: new CustomD1Dialect({ database: config.binding }),
|
||||
plugins
|
||||
plugins,
|
||||
});
|
||||
super(kysely, {}, plugins);
|
||||
}
|
||||
@@ -37,7 +37,7 @@ export class D1Connection extends SqliteConnection {
|
||||
}
|
||||
|
||||
protected override async batch<Queries extends QB[]>(
|
||||
queries: [...Queries]
|
||||
queries: [...Queries],
|
||||
): Promise<{
|
||||
[K in keyof Queries]: Awaited<ReturnType<Queries[K]["execute"]>>;
|
||||
}> {
|
||||
@@ -47,7 +47,7 @@ export class D1Connection extends SqliteConnection {
|
||||
queries.map((q) => {
|
||||
const { sql, parameters } = q.compile();
|
||||
return db.prepare(sql).bind(...parameters);
|
||||
})
|
||||
}),
|
||||
);
|
||||
|
||||
// let it run through plugins
|
||||
|
||||
@@ -8,9 +8,9 @@ import { getBindings } from "./bindings";
|
||||
export function makeSchema(bindings: string[] = []) {
|
||||
return Type.Object(
|
||||
{
|
||||
binding: bindings.length > 0 ? StringEnum(bindings) : Type.Optional(Type.String())
|
||||
binding: bindings.length > 0 ? StringEnum(bindings) : Type.Optional(Type.String()),
|
||||
},
|
||||
{ title: "R2", description: "Cloudflare R2 storage" }
|
||||
{ title: "R2", description: "Cloudflare R2 storage" },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -36,10 +36,10 @@ export function registerMedia(env: Record<string, any>) {
|
||||
override toJSON() {
|
||||
return {
|
||||
...super.toJSON(),
|
||||
config: this.config
|
||||
config: this.config,
|
||||
};
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -67,13 +67,13 @@ export class StorageR2Adapter implements StorageAdapter {
|
||||
}
|
||||
}
|
||||
async listObjects(
|
||||
prefix?: string
|
||||
prefix?: string,
|
||||
): Promise<{ key: string; last_modified: Date; size: number }[]> {
|
||||
const list = await this.bucket.list({ limit: 50 });
|
||||
return list.objects.map((item) => ({
|
||||
key: item.key,
|
||||
size: item.size,
|
||||
last_modified: item.uploaded
|
||||
last_modified: item.uploaded,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ export class StorageR2Adapter implements StorageAdapter {
|
||||
let object: R2ObjectBody | null;
|
||||
const responseHeaders = new Headers({
|
||||
"Accept-Ranges": "bytes",
|
||||
"Content-Type": guess(key)
|
||||
"Content-Type": guess(key),
|
||||
});
|
||||
|
||||
//console.log("getObject:headers", headersToObject(headers));
|
||||
@@ -98,7 +98,7 @@ export class StorageR2Adapter implements StorageAdapter {
|
||||
? {} // miniflare doesn't support range requests
|
||||
: {
|
||||
range: headers,
|
||||
onlyIf: headers
|
||||
onlyIf: headers,
|
||||
};
|
||||
object = (await this.bucket.get(key, options)) as R2ObjectBody;
|
||||
|
||||
@@ -130,7 +130,7 @@ export class StorageR2Adapter implements StorageAdapter {
|
||||
|
||||
return new Response(object.body, {
|
||||
status: object.range ? 206 : 200,
|
||||
headers: responseHeaders
|
||||
headers: responseHeaders,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ export class StorageR2Adapter implements StorageAdapter {
|
||||
if (!metadata || Object.keys(metadata).length === 0) {
|
||||
// guessing is especially required for dev environment (miniflare)
|
||||
metadata = {
|
||||
contentType: guess(object.key)
|
||||
contentType: guess(object.key),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ export class StorageR2Adapter implements StorageAdapter {
|
||||
|
||||
return {
|
||||
type: String(head.httpMetadata?.contentType ?? guess(key)),
|
||||
size: head.size
|
||||
size: head.size,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ export class StorageR2Adapter implements StorageAdapter {
|
||||
toJSON(secrets?: boolean) {
|
||||
return {
|
||||
type: this.getName(),
|
||||
config: {}
|
||||
config: {},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ export function getBindings<T extends GetBindingType>(env: any, type: T): Bindin
|
||||
if (env[key] && (env[key] as any).constructor.name === type) {
|
||||
bindings.push({
|
||||
key,
|
||||
value: env[key] as BindingTypeMap[T]
|
||||
value: env[key] as BindingTypeMap[T],
|
||||
});
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
@@ -84,7 +84,7 @@ export function serve<Env = any>(config: CloudflareBkndConfig<Env> = {}) {
|
||||
hono.all("*", async (c, next) => {
|
||||
const res = await serveStatic({
|
||||
path: `./${pathname}`,
|
||||
manifest: config.manifest!
|
||||
manifest: config.manifest!,
|
||||
})(c as any, next);
|
||||
if (res instanceof Response) {
|
||||
const ttl = 60 * 60 * 24 * 365;
|
||||
@@ -114,6 +114,6 @@ export function serve<Env = any>(config: CloudflareBkndConfig<Env> = {}) {
|
||||
default:
|
||||
throw new Error(`Unknown mode ${mode}`);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ export {
|
||||
getBindings,
|
||||
type BindingTypeMap,
|
||||
type GetBindingType,
|
||||
type BindingMap
|
||||
type BindingMap,
|
||||
} from "./bindings";
|
||||
|
||||
export function d1(config: D1ConnectionConfig) {
|
||||
|
||||
@@ -31,13 +31,13 @@ export async function getCached(config: CloudflareBkndConfig, { env, ctx, ...arg
|
||||
async ({ params: { app } }) => {
|
||||
saveConfig(app.toJSON(true));
|
||||
},
|
||||
"sync"
|
||||
"sync",
|
||||
);
|
||||
await config.beforeBuild?.(app);
|
||||
},
|
||||
adminOptions: { html: config.html }
|
||||
adminOptions: { html: config.html },
|
||||
},
|
||||
{ env, ctx, ...args }
|
||||
{ env, ctx, ...args },
|
||||
);
|
||||
|
||||
if (!cachedConfig) {
|
||||
|
||||
@@ -23,7 +23,7 @@ export async function getDurable(config: CloudflareBkndConfig, ctx: Context) {
|
||||
config: create_config,
|
||||
html: config.html,
|
||||
keepAliveSeconds: config.keepAliveSeconds,
|
||||
setAdminHtml: config.setAdminHtml
|
||||
setAdminHtml: config.setAdminHtml,
|
||||
});
|
||||
|
||||
const headers = new Headers(res.headers);
|
||||
@@ -32,7 +32,7 @@ export async function getDurable(config: CloudflareBkndConfig, ctx: Context) {
|
||||
return new Response(res.body, {
|
||||
status: res.status,
|
||||
statusText: res.statusText,
|
||||
headers
|
||||
headers,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ export class DurableBkndApp extends DurableObject {
|
||||
html?: string;
|
||||
keepAliveSeconds?: number;
|
||||
setAdminHtml?: boolean;
|
||||
}
|
||||
},
|
||||
) {
|
||||
let buildtime = 0;
|
||||
if (!this.app) {
|
||||
@@ -73,7 +73,7 @@ export class DurableBkndApp extends DurableObject {
|
||||
return c.json({
|
||||
id: this.id,
|
||||
keepAliveSeconds: options?.keepAliveSeconds ?? 0,
|
||||
colo: context.colo
|
||||
colo: context.colo,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -82,7 +82,7 @@ export class DurableBkndApp extends DurableObject {
|
||||
adminOptions: { html: options.html },
|
||||
beforeBuild: async (app) => {
|
||||
await this.beforeBuild(app);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
buildtime = performance.now() - start;
|
||||
@@ -101,7 +101,7 @@ export class DurableBkndApp extends DurableObject {
|
||||
return new Response(res.body, {
|
||||
status: res.status,
|
||||
statusText: res.statusText,
|
||||
headers
|
||||
headers,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@ export async function makeApp(config: CloudflareBkndConfig, ctx: Context) {
|
||||
return await createRuntimeApp(
|
||||
{
|
||||
...makeCfConfig(config, ctx),
|
||||
adminOptions: config.html ? { html: config.html } : undefined
|
||||
adminOptions: config.html ? { html: config.html } : undefined,
|
||||
},
|
||||
ctx
|
||||
ctx,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ export function makeConfig<Args = any>(config: BkndConfig<Args>, args?: Args): C
|
||||
|
||||
export async function createFrameworkApp<Args = any>(
|
||||
config: FrameworkBkndConfig,
|
||||
args?: Args
|
||||
args?: Args,
|
||||
): Promise<App> {
|
||||
const app = App.create(makeConfig(config, args));
|
||||
|
||||
@@ -44,7 +44,7 @@ export async function createFrameworkApp<Args = any>(
|
||||
async () => {
|
||||
await config.onBuilt?.(app);
|
||||
},
|
||||
"sync"
|
||||
"sync",
|
||||
);
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ export async function createRuntimeApp<Env = any>(
|
||||
serveStatic?: MiddlewareHandler | [string, MiddlewareHandler];
|
||||
adminOptions?: AdminControllerOptions | false;
|
||||
},
|
||||
env?: Env
|
||||
env?: Env,
|
||||
): Promise<App> {
|
||||
const app = App.create(makeConfig(config, env));
|
||||
|
||||
@@ -82,7 +82,7 @@ export async function createRuntimeApp<Env = any>(
|
||||
app.registerAdminController(adminOptions);
|
||||
}
|
||||
},
|
||||
"sync"
|
||||
"sync",
|
||||
);
|
||||
|
||||
await config.beforeBuild?.(app);
|
||||
|
||||
@@ -34,7 +34,7 @@ function getCleanRequest(req: Request, cleanRequest: NextjsBkndConfig["cleanRequ
|
||||
return new Request(url.toString(), {
|
||||
method: req.method,
|
||||
headers: req.headers,
|
||||
body: req.body
|
||||
body: req.body,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { registries } from "bknd";
|
||||
import {
|
||||
type LocalAdapterConfig,
|
||||
StorageLocalAdapter
|
||||
StorageLocalAdapter,
|
||||
} from "../../media/storage/adapters/StorageLocalAdapter";
|
||||
|
||||
export * from "./node.adapter";
|
||||
|
||||
@@ -24,7 +24,7 @@ export function serve({
|
||||
}: NodeBkndConfig = {}) {
|
||||
const root = path.relative(
|
||||
process.cwd(),
|
||||
path.resolve(distPath ?? relativeDistPath ?? "./node_modules/bknd/dist", "static")
|
||||
path.resolve(distPath ?? relativeDistPath ?? "./node_modules/bknd/dist", "static"),
|
||||
);
|
||||
if (relativeDistPath) {
|
||||
console.warn("relativeDistPath is deprecated, please use distPath instead");
|
||||
@@ -41,16 +41,16 @@ export function serve({
|
||||
registerLocalMediaAdapter();
|
||||
app = await createRuntimeApp({
|
||||
...config,
|
||||
serveStatic: serveStatic({ root })
|
||||
serveStatic: serveStatic({ root }),
|
||||
});
|
||||
}
|
||||
|
||||
return app.fetch(req);
|
||||
}
|
||||
},
|
||||
},
|
||||
(connInfo) => {
|
||||
console.log(`Server is running on http://localhost:${connInfo.port}`);
|
||||
listener?.(connInfo);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ export async function getApp<Args extends RemixContext = RemixContext>(
|
||||
}
|
||||
|
||||
export function serve<Args extends RemixContext = RemixContext>(
|
||||
config: RemixBkndConfig<Args> = {}
|
||||
config: RemixBkndConfig<Args> = {},
|
||||
) {
|
||||
return async (args: Args) => {
|
||||
app = await getApp(config, args);
|
||||
|
||||
@@ -20,6 +20,6 @@ export function nodeRequestToRequest(req: IncomingMessage): Request {
|
||||
const method = req.method || "GET";
|
||||
return new Request(url, {
|
||||
method,
|
||||
headers
|
||||
headers,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ export const devServerConfig = {
|
||||
/^\/@.+$/,
|
||||
/\/components.*?\.json.*/, // @todo: improve
|
||||
/^\/(public|assets|static)\/.+/,
|
||||
/^\/node_modules\/.*/
|
||||
/^\/node_modules\/.*/,
|
||||
] as any,
|
||||
injectClientScript: false
|
||||
injectClientScript: false,
|
||||
} as const;
|
||||
|
||||
@@ -24,7 +24,7 @@ window.__vite_plugin_react_preamble_installed__ = true
|
||||
</script>
|
||||
<script type="module" src="/@vite/client"></script>
|
||||
${addBkndContext ? "<!-- BKND_CONTEXT -->" : ""}
|
||||
</head>`
|
||||
</head>`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -39,12 +39,12 @@ async function createApp(config: ViteBkndConfig = {}, env?: any) {
|
||||
: {
|
||||
html: config.html,
|
||||
forceDev: config.forceDev ?? {
|
||||
mainPath: "/src/main.tsx"
|
||||
}
|
||||
mainPath: "/src/main.tsx",
|
||||
},
|
||||
},
|
||||
serveStatic: ["/assets/*", serveStatic({ root: config.distPath ?? "./" })]
|
||||
serveStatic: ["/assets/*", serveStatic({ root: config.distPath ?? "./" })],
|
||||
},
|
||||
env
|
||||
env,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ export function serveFresh(config: Omit<ViteBkndConfig, "mode"> = {}) {
|
||||
async fetch(request: Request, env: any, ctx: ExecutionContext) {
|
||||
const app = await createApp(config, env);
|
||||
return app.fetch(request, env, ctx);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ export function serveCached(config: Omit<ViteBkndConfig, "mode"> = {}) {
|
||||
}
|
||||
|
||||
return app.fetch(request, env, ctx);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -77,6 +77,6 @@ export function serve({ mode, ...config }: ViteBkndConfig = {}) {
|
||||
export function devServer(options: DevServerOptions) {
|
||||
return honoViteDevServer({
|
||||
...devServerConfig,
|
||||
...options
|
||||
...options,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user