create-better-t-stack 2.40.3-canary.34eb1c18 → 2.40.3-canary.50a1b944
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/dist/{src-5v1dq5ez.js → src-D59j3XG5.js} +18 -25
- package/package.json +1 -1
- package/templates/api/orpc/server/next/src/app/rpc/[...all]/route.ts.hbs +3 -20
- package/templates/backend/server/elysia/src/index.ts.hbs +2 -19
- package/templates/backend/server/express/src/index.ts.hbs +4 -26
- package/templates/backend/server/fastify/src/index.ts.hbs +2 -22
- package/templates/backend/server/hono/src/index.ts.hbs +5 -28
package/dist/cli.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -110,8 +110,6 @@ const dependencyVersionMap = {
|
|
|
110
110
|
streamdown: "^1.1.6",
|
|
111
111
|
"@orpc/server": "^1.8.6",
|
|
112
112
|
"@orpc/client": "^1.8.6",
|
|
113
|
-
"@orpc/openapi": "^1.8.6",
|
|
114
|
-
"@orpc/zod": "^1.8.6",
|
|
115
113
|
"@orpc/tanstack-query": "^1.8.6",
|
|
116
114
|
"@trpc/tanstack-react-query": "^11.5.0",
|
|
117
115
|
"@trpc/server": "^11.5.0",
|
|
@@ -498,8 +496,6 @@ function ensureSingleWebAndNative(frontends) {
|
|
|
498
496
|
function validateWorkersCompatibility(providedFlags, options, config) {
|
|
499
497
|
if (providedFlags.has("runtime") && options.runtime === "workers" && config.backend && config.backend !== "hono") exitWithError(`Cloudflare Workers runtime (--runtime workers) is only supported with Hono backend (--backend hono). Current backend: ${config.backend}. Please use '--backend hono' or choose a different runtime.`);
|
|
500
498
|
if (providedFlags.has("backend") && config.backend && config.backend !== "hono" && config.runtime === "workers") exitWithError(`Backend '${config.backend}' is not compatible with Cloudflare Workers runtime. Cloudflare Workers runtime is only supported with Hono backend. Please use '--backend hono' or choose a different runtime.`);
|
|
501
|
-
if (providedFlags.has("runtime") && options.runtime === "workers" && config.orm && config.orm !== "drizzle" && config.orm !== "none") exitWithError(`Cloudflare Workers runtime (--runtime workers) is only supported with Drizzle ORM (--orm drizzle) or no ORM (--orm none). Current ORM: ${config.orm}. Please use '--orm drizzle', '--orm none', or choose a different runtime.`);
|
|
502
|
-
if (providedFlags.has("orm") && config.orm && config.orm !== "drizzle" && config.orm !== "none" && config.runtime === "workers") exitWithError(`ORM '${config.orm}' is not compatible with Cloudflare Workers runtime. Cloudflare Workers runtime is only supported with Drizzle ORM or no ORM. Please use '--orm drizzle', '--orm none', or choose a different runtime.`);
|
|
503
499
|
if (providedFlags.has("runtime") && options.runtime === "workers" && config.database === "mongodb") exitWithError("Cloudflare Workers runtime (--runtime workers) is not compatible with MongoDB database. MongoDB requires Prisma or Mongoose ORM, but Workers runtime only supports Drizzle ORM. Please use a different database or runtime.");
|
|
504
500
|
if (providedFlags.has("runtime") && options.runtime === "workers" && config.dbSetup === "docker") exitWithError("Cloudflare Workers runtime (--runtime workers) is not compatible with Docker setup. Workers runtime uses serverless databases (D1) and doesn't support local Docker containers. Please use '--db-setup d1' for SQLite or choose a different runtime.");
|
|
505
501
|
if (providedFlags.has("database") && config.database === "mongodb" && config.runtime === "workers") exitWithError("MongoDB database is not compatible with Cloudflare Workers runtime. MongoDB requires Prisma or Mongoose ORM, but Workers runtime only supports Drizzle ORM. Please use a different database or runtime.");
|
|
@@ -997,12 +993,11 @@ async function getORMChoice(orm, hasDatabase, database, backend, runtime) {
|
|
|
997
993
|
if (backend === "convex") return "none";
|
|
998
994
|
if (!hasDatabase) return "none";
|
|
999
995
|
if (orm !== void 0) return orm;
|
|
1000
|
-
if (runtime === "workers") return "drizzle";
|
|
1001
996
|
const options = [...database === "mongodb" ? [ormOptions.prisma, ormOptions.mongoose] : [ormOptions.drizzle, ormOptions.prisma]];
|
|
1002
997
|
const response = await select({
|
|
1003
998
|
message: "Select ORM",
|
|
1004
999
|
options,
|
|
1005
|
-
initialValue: database === "mongodb" ? "prisma" : DEFAULT_CONFIG.orm
|
|
1000
|
+
initialValue: database === "mongodb" ? "prisma" : runtime === "workers" ? "drizzle" : DEFAULT_CONFIG.orm
|
|
1006
1001
|
});
|
|
1007
1002
|
if (isCancel(response)) return exitCancelled("Operation cancelled");
|
|
1008
1003
|
return response;
|
|
@@ -3098,7 +3093,8 @@ async function setupNextAlchemyDeploy(projectDir, _packageManager, options) {
|
|
|
3098
3093
|
if (!options?.skipAppScripts) pkg.scripts = {
|
|
3099
3094
|
...pkg.scripts,
|
|
3100
3095
|
deploy: "alchemy deploy",
|
|
3101
|
-
destroy: "alchemy destroy"
|
|
3096
|
+
destroy: "alchemy destroy",
|
|
3097
|
+
dev: "alchemy dev"
|
|
3102
3098
|
};
|
|
3103
3099
|
await fs.writeJson(pkgPath, pkg, { spaces: 2 });
|
|
3104
3100
|
}
|
|
@@ -3123,7 +3119,8 @@ async function setupNuxtAlchemyDeploy(projectDir, _packageManager, options) {
|
|
|
3123
3119
|
if (!options?.skipAppScripts) pkg.scripts = {
|
|
3124
3120
|
...pkg.scripts,
|
|
3125
3121
|
deploy: "alchemy deploy",
|
|
3126
|
-
destroy: "alchemy destroy"
|
|
3122
|
+
destroy: "alchemy destroy",
|
|
3123
|
+
dev: "alchemy dev"
|
|
3127
3124
|
};
|
|
3128
3125
|
await fs.writeJson(pkgPath, pkg, { spaces: 2 });
|
|
3129
3126
|
}
|
|
@@ -3186,7 +3183,8 @@ async function setupReactRouterAlchemyDeploy(projectDir, _packageManager, option
|
|
|
3186
3183
|
if (!options?.skipAppScripts) pkg.scripts = {
|
|
3187
3184
|
...pkg.scripts,
|
|
3188
3185
|
deploy: "alchemy deploy",
|
|
3189
|
-
destroy: "alchemy destroy"
|
|
3186
|
+
destroy: "alchemy destroy",
|
|
3187
|
+
dev: "alchemy dev"
|
|
3190
3188
|
};
|
|
3191
3189
|
await fs.writeJson(pkgPath, pkg, { spaces: 2 });
|
|
3192
3190
|
}
|
|
@@ -3207,7 +3205,8 @@ async function setupSolidAlchemyDeploy(projectDir, _packageManager, options) {
|
|
|
3207
3205
|
if (!options?.skipAppScripts) pkg.scripts = {
|
|
3208
3206
|
...pkg.scripts,
|
|
3209
3207
|
deploy: "alchemy deploy",
|
|
3210
|
-
destroy: "alchemy destroy"
|
|
3208
|
+
destroy: "alchemy destroy",
|
|
3209
|
+
dev: "alchemy dev"
|
|
3211
3210
|
};
|
|
3212
3211
|
await fs.writeJson(pkgPath, pkg, { spaces: 2 });
|
|
3213
3212
|
}
|
|
@@ -3232,7 +3231,8 @@ async function setupSvelteAlchemyDeploy(projectDir, _packageManager, options) {
|
|
|
3232
3231
|
if (!options?.skipAppScripts) pkg.scripts = {
|
|
3233
3232
|
...pkg.scripts,
|
|
3234
3233
|
deploy: "alchemy deploy",
|
|
3235
|
-
destroy: "alchemy destroy"
|
|
3234
|
+
destroy: "alchemy destroy",
|
|
3235
|
+
dev: "alchemy dev"
|
|
3236
3236
|
};
|
|
3237
3237
|
await fs.writeJson(pkgPath, pkg, { spaces: 2 });
|
|
3238
3238
|
}
|
|
@@ -3298,7 +3298,8 @@ async function setupTanStackRouterAlchemyDeploy(projectDir, _packageManager, opt
|
|
|
3298
3298
|
if (!options?.skipAppScripts) pkg.scripts = {
|
|
3299
3299
|
...pkg.scripts,
|
|
3300
3300
|
deploy: "alchemy deploy",
|
|
3301
|
-
destroy: "alchemy destroy"
|
|
3301
|
+
destroy: "alchemy destroy",
|
|
3302
|
+
dev: "alchemy dev"
|
|
3302
3303
|
};
|
|
3303
3304
|
await fs.writeJson(pkgPath, pkg, { spaces: 2 });
|
|
3304
3305
|
}
|
|
@@ -3323,7 +3324,8 @@ async function setupTanStackStartAlchemyDeploy(projectDir, _packageManager, opti
|
|
|
3323
3324
|
if (!options?.skipAppScripts) pkg.scripts = {
|
|
3324
3325
|
...pkg.scripts,
|
|
3325
3326
|
deploy: "alchemy deploy",
|
|
3326
|
-
destroy: "alchemy destroy"
|
|
3327
|
+
destroy: "alchemy destroy",
|
|
3328
|
+
dev: "alchemy dev"
|
|
3327
3329
|
};
|
|
3328
3330
|
await fs.writeJson(pkgPath, pkg, { spaces: 2 });
|
|
3329
3331
|
}
|
|
@@ -3887,12 +3889,7 @@ function getFrontendType(frontend) {
|
|
|
3887
3889
|
}
|
|
3888
3890
|
function getApiDependencies(api, frontendType) {
|
|
3889
3891
|
const deps = {};
|
|
3890
|
-
if (api === "orpc") deps.server = { dependencies: [
|
|
3891
|
-
"@orpc/server",
|
|
3892
|
-
"@orpc/client",
|
|
3893
|
-
"@orpc/openapi",
|
|
3894
|
-
"@orpc/zod"
|
|
3895
|
-
] };
|
|
3892
|
+
if (api === "orpc") deps.server = { dependencies: ["@orpc/server", "@orpc/client"] };
|
|
3896
3893
|
else if (api === "trpc") deps.server = { dependencies: ["@trpc/server", "@trpc/client"] };
|
|
3897
3894
|
if (frontendType.hasReactWeb) {
|
|
3898
3895
|
if (api === "orpc") deps.web = { dependencies: ["@orpc/tanstack-query", "@orpc/client"] };
|
|
@@ -5740,7 +5737,7 @@ async function getDockerStatus(database) {
|
|
|
5740
5737
|
//#endregion
|
|
5741
5738
|
//#region src/helpers/core/post-installation.ts
|
|
5742
5739
|
async function displayPostInstallInstructions(config) {
|
|
5743
|
-
const {
|
|
5740
|
+
const { database, relativePath, packageManager, depsInstalled, orm, addons, runtime, frontend, backend, dbSetup, webDeploy, serverDeploy } = config;
|
|
5744
5741
|
const isConvex = backend === "convex";
|
|
5745
5742
|
const runCmd = packageManager === "npm" ? "npm run" : packageManager === "pnpm" ? "pnpm run" : "bun run";
|
|
5746
5743
|
const cdCmd = `cd ${relativePath}`;
|
|
@@ -5788,11 +5785,7 @@ async function displayPostInstallInstructions(config) {
|
|
|
5788
5785
|
output += `${pc.bold("Your project will be available at:")}\n`;
|
|
5789
5786
|
if (hasWeb) output += `${pc.cyan("•")} Frontend: http://localhost:${webPort}\n`;
|
|
5790
5787
|
else if (!hasNative && !addons?.includes("starlight")) output += `${pc.yellow("NOTE:")} You are creating a backend-only app\n (no frontend selected)\n`;
|
|
5791
|
-
if (!isConvex) {
|
|
5792
|
-
output += `${pc.cyan("•")} Backend API: http://localhost:3000\n`;
|
|
5793
|
-
if (api === "orpc") if (backend === "next") output += `${pc.cyan("•")} OpenAPI (Scalar UI): http://localhost:3000/rpc/api\n`;
|
|
5794
|
-
else output += `${pc.cyan("•")} OpenAPI (Scalar UI): http://localhost:3000/api\n`;
|
|
5795
|
-
}
|
|
5788
|
+
if (!isConvex) output += `${pc.cyan("•")} Backend API: http://localhost:3000\n`;
|
|
5796
5789
|
if (addons?.includes("starlight")) output += `${pc.cyan("•")} Docs: http://localhost:4321\n`;
|
|
5797
5790
|
if (addons?.includes("fumadocs")) output += `${pc.cyan("•")} Fumadocs: http://localhost:4000\n`;
|
|
5798
5791
|
if (nativeInstructions) output += `\n${nativeInstructions.trim()}\n`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-better-t-stack",
|
|
3
|
-
"version": "2.40.3-canary.
|
|
3
|
+
"version": "2.40.3-canary.50a1b944",
|
|
4
4
|
"description": "A modern CLI tool for scaffolding end-to-end type-safe TypeScript projects with best practices and customizable configurations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -2,35 +2,18 @@
|
|
|
2
2
|
import { createContext } from '@/lib/context'
|
|
3
3
|
{{/if}}
|
|
4
4
|
import { appRouter } from '@/routers'
|
|
5
|
-
import { OpenAPIHandler } from '@orpc/openapi/fetch'
|
|
6
|
-
import { OpenAPIReferencePlugin } from '@orpc/openapi/plugins'
|
|
7
|
-
import { ZodToJsonSchemaConverter } from '@orpc/zod/zod4'
|
|
8
5
|
import { RPCHandler } from '@orpc/server/fetch'
|
|
9
6
|
import { NextRequest } from 'next/server'
|
|
10
7
|
|
|
11
|
-
const
|
|
12
|
-
const apiHandler = new OpenAPIHandler(appRouter, {
|
|
13
|
-
plugins: [
|
|
14
|
-
new OpenAPIReferencePlugin({
|
|
15
|
-
schemaConverters: [new ZodToJsonSchemaConverter()],
|
|
16
|
-
}),
|
|
17
|
-
],
|
|
18
|
-
})
|
|
8
|
+
const handler = new RPCHandler(appRouter)
|
|
19
9
|
|
|
20
10
|
async function handleRequest(req: NextRequest) {
|
|
21
|
-
const
|
|
11
|
+
const { response } = await handler.handle(req, {
|
|
22
12
|
prefix: '/rpc',
|
|
23
13
|
context: {{#if (eq auth "better-auth")}}await createContext(req){{else}}{}{{/if}},
|
|
24
14
|
})
|
|
25
|
-
if (rpcResult.response) return rpcResult.response
|
|
26
15
|
|
|
27
|
-
|
|
28
|
-
prefix: '/rpc/api',
|
|
29
|
-
context: {{#if (eq auth "better-auth")}}await createContext(req){{else}}{}{{/if}},
|
|
30
|
-
})
|
|
31
|
-
if (apiResult.response) return apiResult.response
|
|
32
|
-
|
|
33
|
-
return new Response('Not found', { status: 404 })
|
|
16
|
+
return response ?? new Response('Not found', { status: 404 })
|
|
34
17
|
}
|
|
35
18
|
|
|
36
19
|
export const GET = handleRequest
|
|
@@ -10,9 +10,6 @@ import { appRouter } from "./routers/index";
|
|
|
10
10
|
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
|
|
11
11
|
{{/if}}
|
|
12
12
|
{{#if (eq api "orpc")}}
|
|
13
|
-
import { OpenAPIHandler } from "@orpc/openapi/fetch";
|
|
14
|
-
import { OpenAPIReferencePlugin } from "@orpc/openapi/plugins";
|
|
15
|
-
import { ZodToJsonSchemaConverter } from "@orpc/zod/zod4";
|
|
16
13
|
import { RPCHandler } from "@orpc/server/fetch";
|
|
17
14
|
import { appRouter } from "./routers";
|
|
18
15
|
import { createContext } from "./lib/context";
|
|
@@ -22,14 +19,7 @@ import { auth } from "./lib/auth";
|
|
|
22
19
|
{{/if}}
|
|
23
20
|
|
|
24
21
|
{{#if (eq api "orpc")}}
|
|
25
|
-
const
|
|
26
|
-
const apiHandler = new OpenAPIHandler(appRouter, {
|
|
27
|
-
plugins: [
|
|
28
|
-
new OpenAPIReferencePlugin({
|
|
29
|
-
schemaConverters: [new ZodToJsonSchemaConverter()],
|
|
30
|
-
}),
|
|
31
|
-
],
|
|
32
|
-
});
|
|
22
|
+
const handler = new RPCHandler(appRouter);
|
|
33
23
|
{{/if}}
|
|
34
24
|
|
|
35
25
|
{{#if (eq runtime "node")}}
|
|
@@ -58,19 +48,12 @@ const app = new Elysia()
|
|
|
58
48
|
{{/if}}
|
|
59
49
|
{{#if (eq api "orpc")}}
|
|
60
50
|
.all('/rpc*', async (context) => {
|
|
61
|
-
const { response } = await
|
|
51
|
+
const { response } = await handler.handle(context.request, {
|
|
62
52
|
prefix: '/rpc',
|
|
63
53
|
context: await createContext({ context })
|
|
64
54
|
})
|
|
65
55
|
return response ?? new Response('Not Found', { status: 404 })
|
|
66
56
|
})
|
|
67
|
-
.all('/api*', async (context) => {
|
|
68
|
-
const { response } = await apiHandler.handle(context.request, {
|
|
69
|
-
prefix: '/api',
|
|
70
|
-
context: await createContext({ context })
|
|
71
|
-
})
|
|
72
|
-
return response ?? new Response('Not Found', { status: 404 })
|
|
73
|
-
})
|
|
74
57
|
{{/if}}
|
|
75
58
|
{{#if (eq api "trpc")}}
|
|
76
59
|
.all("/trpc/*", async (context) => {
|
|
@@ -5,9 +5,6 @@ import { createContext } from "./lib/context";
|
|
|
5
5
|
import { appRouter } from "./routers/index";
|
|
6
6
|
{{/if}}
|
|
7
7
|
{{#if (eq api "orpc")}}
|
|
8
|
-
import { OpenAPIHandler } from "@orpc/openapi/node";
|
|
9
|
-
import { OpenAPIReferencePlugin } from "@orpc/openapi/plugins";
|
|
10
|
-
import { ZodToJsonSchemaConverter } from "@orpc/zod/zod4";
|
|
11
8
|
import { RPCHandler } from "@orpc/server/node";
|
|
12
9
|
import { appRouter } from "./routers";
|
|
13
10
|
{{#if (eq auth "better-auth")}}
|
|
@@ -53,17 +50,9 @@ app.use(
|
|
|
53
50
|
{{/if}}
|
|
54
51
|
|
|
55
52
|
{{#if (eq api "orpc")}}
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
new OpenAPIReferencePlugin({
|
|
60
|
-
schemaConverters: [new ZodToJsonSchemaConverter()],
|
|
61
|
-
}),
|
|
62
|
-
],
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
app.use(async (req, res, next) => {
|
|
66
|
-
const rpcResult = await rpcHandler.handle(req, res, {
|
|
53
|
+
const handler = new RPCHandler(appRouter);
|
|
54
|
+
app.use("/rpc{*path}", async (req, res, next) => {
|
|
55
|
+
const { matched } = await handler.handle(req, res, {
|
|
67
56
|
prefix: "/rpc",
|
|
68
57
|
{{#if (eq auth "better-auth")}}
|
|
69
58
|
context: await createContext({ req }),
|
|
@@ -71,18 +60,7 @@ app.use(async (req, res, next) => {
|
|
|
71
60
|
context: {},
|
|
72
61
|
{{/if}}
|
|
73
62
|
});
|
|
74
|
-
if (
|
|
75
|
-
|
|
76
|
-
const apiResult = await apiHandler.handle(req, res, {
|
|
77
|
-
prefix: "/api",
|
|
78
|
-
{{#if (eq auth "better-auth")}}
|
|
79
|
-
context: await createContext({ req }),
|
|
80
|
-
{{else}}
|
|
81
|
-
context: {},
|
|
82
|
-
{{/if}}
|
|
83
|
-
});
|
|
84
|
-
if (apiResult.matched) return;
|
|
85
|
-
|
|
63
|
+
if (matched) return;
|
|
86
64
|
next();
|
|
87
65
|
});
|
|
88
66
|
{{/if}}
|
|
@@ -9,9 +9,6 @@ import { appRouter, type AppRouter } from "./routers/index";
|
|
|
9
9
|
{{/if}}
|
|
10
10
|
|
|
11
11
|
{{#if (eq api "orpc")}}
|
|
12
|
-
import { OpenAPIHandler } from "@orpc/openapi/node";
|
|
13
|
-
import { OpenAPIReferencePlugin } from "@orpc/openapi/plugins";
|
|
14
|
-
import { ZodToJsonSchemaConverter } from "@orpc/zod/zod4";
|
|
15
12
|
import { RPCHandler } from "@orpc/server/node";
|
|
16
13
|
import { CORSPlugin } from "@orpc/server/plugins";
|
|
17
14
|
import { appRouter } from "./routers/index";
|
|
@@ -43,7 +40,7 @@ const baseCorsConfig = {
|
|
|
43
40
|
};
|
|
44
41
|
|
|
45
42
|
{{#if (eq api "orpc")}}
|
|
46
|
-
const
|
|
43
|
+
const handler = new RPCHandler(appRouter, {
|
|
47
44
|
plugins: [
|
|
48
45
|
new CORSPlugin({
|
|
49
46
|
origin: process.env.CORS_ORIGIN,
|
|
@@ -53,19 +50,11 @@ const rpcHandler = new RPCHandler(appRouter, {
|
|
|
53
50
|
],
|
|
54
51
|
});
|
|
55
52
|
|
|
56
|
-
const apiHandler = new OpenAPIHandler(appRouter, {
|
|
57
|
-
plugins: [
|
|
58
|
-
new OpenAPIReferencePlugin({
|
|
59
|
-
schemaConverters: [new ZodToJsonSchemaConverter()],
|
|
60
|
-
}),
|
|
61
|
-
],
|
|
62
|
-
});
|
|
63
|
-
|
|
64
53
|
const fastify = Fastify({
|
|
65
54
|
logger: true,
|
|
66
55
|
serverFactory: (fastifyHandler) => {
|
|
67
56
|
const server = createServer(async (req, res) => {
|
|
68
|
-
const { matched } = await
|
|
57
|
+
const { matched } = await handler.handle(req, res, {
|
|
69
58
|
context: await createContext(req.headers),
|
|
70
59
|
prefix: "/rpc",
|
|
71
60
|
});
|
|
@@ -74,15 +63,6 @@ const fastify = Fastify({
|
|
|
74
63
|
return;
|
|
75
64
|
}
|
|
76
65
|
|
|
77
|
-
const apiResult = await apiHandler.handle(req, res, {
|
|
78
|
-
context: await createContext(req.headers),
|
|
79
|
-
prefix: "/api",
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
if (apiResult.matched) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
66
|
fastifyHandler(req, res);
|
|
87
67
|
});
|
|
88
68
|
|
|
@@ -5,9 +5,6 @@ import "dotenv/config";
|
|
|
5
5
|
import { env } from "cloudflare:workers";
|
|
6
6
|
{{/if}}
|
|
7
7
|
{{#if (eq api "orpc")}}
|
|
8
|
-
import { OpenAPIHandler } from "@orpc/openapi/fetch";
|
|
9
|
-
import { OpenAPIReferencePlugin } from "@orpc/openapi/plugins";
|
|
10
|
-
import { ZodToJsonSchemaConverter } from "@orpc/zod/zod4";
|
|
11
8
|
import { RPCHandler } from "@orpc/server/fetch";
|
|
12
9
|
import { createContext } from "./lib/context";
|
|
13
10
|
import { appRouter } from "./routers/index";
|
|
@@ -57,37 +54,17 @@ app.on(["POST", "GET"], "/api/auth/**", (c) => auth.handler(c.req.raw));
|
|
|
57
54
|
{{/if}}
|
|
58
55
|
|
|
59
56
|
{{#if (eq api "orpc")}}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
new OpenAPIReferencePlugin({
|
|
63
|
-
schemaConverters: [new ZodToJsonSchemaConverter()],
|
|
64
|
-
}),
|
|
65
|
-
],
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
export const rpcHandler = new RPCHandler(appRouter);
|
|
69
|
-
|
|
70
|
-
app.use("/*", async (c, next) => {
|
|
57
|
+
const handler = new RPCHandler(appRouter);
|
|
58
|
+
app.use("/rpc/*", async (c, next) => {
|
|
71
59
|
const context = await createContext({ context: c });
|
|
72
|
-
|
|
73
|
-
const rpcResult = await rpcHandler.handle(c.req.raw, {
|
|
60
|
+
const { matched, response } = await handler.handle(c.req.raw, {
|
|
74
61
|
prefix: "/rpc",
|
|
75
62
|
context: context,
|
|
76
63
|
});
|
|
77
64
|
|
|
78
|
-
if (
|
|
79
|
-
return c.newResponse(
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const apiResult = await apiHandler.handle(c.req.raw, {
|
|
83
|
-
prefix: "/api",
|
|
84
|
-
context: context,
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
if (apiResult.matched) {
|
|
88
|
-
return c.newResponse(apiResult.response.body, apiResult.response);
|
|
65
|
+
if (matched) {
|
|
66
|
+
return c.newResponse(response.body, response);
|
|
89
67
|
}
|
|
90
|
-
|
|
91
68
|
await next();
|
|
92
69
|
});
|
|
93
70
|
{{/if}}
|