mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
init: nuxt adapter
This commit is contained in:
@@ -335,6 +335,11 @@ async function buildAdapters() {
|
||||
platform: "node",
|
||||
}),
|
||||
|
||||
tsup.build({
|
||||
...baseConfig("nuxt"),
|
||||
platform: "node",
|
||||
}),
|
||||
|
||||
tsup.build({
|
||||
...baseConfig("node"),
|
||||
platform: "node",
|
||||
|
||||
@@ -15,6 +15,9 @@ const configs = {
|
||||
nextjs: {
|
||||
base_path: "/admin",
|
||||
},
|
||||
nuxt: {
|
||||
base_path: "/admin",
|
||||
},
|
||||
astro: {
|
||||
base_path: "/admin",
|
||||
},
|
||||
|
||||
@@ -233,6 +233,11 @@
|
||||
"import": "./dist/adapter/nextjs/index.js",
|
||||
"require": "./dist/adapter/nextjs/index.js"
|
||||
},
|
||||
"./adapter/nuxt": {
|
||||
"types": "./dist/types/adapter/nuxt/index.d.ts",
|
||||
"import": "./dist/adapter/nuxt/index.js",
|
||||
"require": "./dist/adapter/nuxt/index.js"
|
||||
},
|
||||
"./adapter/react-router": {
|
||||
"types": "./dist/types/adapter/react-router/index.d.ts",
|
||||
"import": "./dist/adapter/react-router/index.js",
|
||||
@@ -287,6 +292,7 @@
|
||||
"adapter/cloudflare": ["./dist/types/adapter/cloudflare/index.d.ts"],
|
||||
"adapter/vite": ["./dist/types/adapter/vite/index.d.ts"],
|
||||
"adapter/nextjs": ["./dist/types/adapter/nextjs/index.d.ts"],
|
||||
"adapter/nuxt": ["./dist/types/adapter/nuxt/index.d.ts"],
|
||||
"adapter/react-router": ["./dist/types/adapter/react-router/index.d.ts"],
|
||||
"adapter/bun": ["./dist/types/adapter/bun/index.d.ts"],
|
||||
"adapter/node": ["./dist/types/adapter/node/index.d.ts"],
|
||||
@@ -318,6 +324,7 @@
|
||||
"serverless",
|
||||
"cloudflare",
|
||||
"nextjs",
|
||||
"nuxt",
|
||||
"remix",
|
||||
"react-router",
|
||||
"astro",
|
||||
|
||||
1
app/src/adapter/nuxt/index.ts
Normal file
1
app/src/adapter/nuxt/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./nuxt.adapter";
|
||||
15
app/src/adapter/nuxt/nuxt.adapter.spec.ts
Normal file
15
app/src/adapter/nuxt/nuxt.adapter.spec.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { afterAll, beforeAll, describe } from "bun:test";
|
||||
import * as nuxt from "./nuxt.adapter";
|
||||
import { disableConsoleLog, enableConsoleLog } from "core/utils";
|
||||
import { adapterTestSuite } from "adapter/adapter-test-suite";
|
||||
import { bunTestRunner } from "adapter/bun/test";
|
||||
|
||||
beforeAll(disableConsoleLog);
|
||||
afterAll(enableConsoleLog);
|
||||
|
||||
describe("nuxt adapter", () => {
|
||||
adapterTestSuite(bunTestRunner, {
|
||||
makeApp: nuxt.getApp,
|
||||
makeHandler: nuxt.serve,
|
||||
});
|
||||
});
|
||||
30
app/src/adapter/nuxt/nuxt.adapter.ts
Normal file
30
app/src/adapter/nuxt/nuxt.adapter.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { createRuntimeApp, type RuntimeBkndConfig } from "bknd/adapter";
|
||||
|
||||
export type NuxtEnv = NodeJS.ProcessEnv;
|
||||
export type NuxtBkndConfig<Env = NuxtEnv> = RuntimeBkndConfig<Env>;
|
||||
|
||||
/**
|
||||
* Get bknd app instance
|
||||
* @param config - bknd configuration
|
||||
* @param args - environment variables
|
||||
*/
|
||||
export async function getApp<Env>(
|
||||
config: NuxtBkndConfig<Env> = {} as NuxtBkndConfig<Env>,
|
||||
args: Env,
|
||||
) {
|
||||
return await createRuntimeApp(config, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create middleware handler for Nuxt
|
||||
* @param config - bknd configuration
|
||||
* @param args - environment variables
|
||||
*/
|
||||
export function serve<Env>(
|
||||
config: NuxtBkndConfig<Env> = {} as NuxtBkndConfig<Env>,
|
||||
args: Env,
|
||||
) {
|
||||
return async (request: Request) => {
|
||||
return (await getApp(config, args)).fetch(request);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user