eddev 2.0.0-beta.60 → 2.0.0-beta.61
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/app/server/server-context.d.ts +2 -0
- package/dist/app/server/server-context.js +2 -0
- package/dist/node/cli/version.d.ts +1 -1
- package/dist/node/cli/version.js +1 -1
- package/dist/node/compiler/vinxi-app.js +18 -36
- package/dist/node/compiler/vinxi-codegen.js +46 -78
- package/package.json +1 -1
|
@@ -6,6 +6,7 @@ export type ServerContextArgs = {
|
|
|
6
6
|
dev: boolean;
|
|
7
7
|
origin: string;
|
|
8
8
|
replaceUrls?: UrlReplacerConf;
|
|
9
|
+
rpcBases?: string[];
|
|
9
10
|
};
|
|
10
11
|
export type ServerContextRuntime = {
|
|
11
12
|
getManifest: (name: string) => Manifest;
|
|
@@ -21,6 +22,7 @@ export declare class ServerContext {
|
|
|
21
22
|
dev: boolean;
|
|
22
23
|
origin: string;
|
|
23
24
|
replaceUrls?: (text: string) => string;
|
|
25
|
+
rpcBases: string[];
|
|
24
26
|
static main: ServerContext;
|
|
25
27
|
constructor(conf: ServerContextArgs);
|
|
26
28
|
get runtime(): ServerContextRuntime;
|
|
@@ -18,10 +18,12 @@ export class ServerContext {
|
|
|
18
18
|
dev;
|
|
19
19
|
origin;
|
|
20
20
|
replaceUrls;
|
|
21
|
+
rpcBases = [];
|
|
21
22
|
static main;
|
|
22
23
|
constructor(conf) {
|
|
23
24
|
this.dev = conf.dev;
|
|
24
25
|
this.origin = conf.origin;
|
|
26
|
+
this.rpcBases = conf.rpcBases ?? [];
|
|
25
27
|
if (conf.replaceUrls) {
|
|
26
28
|
this.replaceUrls = createUrlReplacer(conf.replaceUrls);
|
|
27
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "2.0.0-beta.
|
|
1
|
+
export declare const VERSION = "2.0.0-beta.61";
|
package/dist/node/cli/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "2.0.0-beta.
|
|
1
|
+
export const VERSION = "2.0.0-beta.61";
|
|
@@ -77,24 +77,6 @@ export function createVinxiApp(args) {
|
|
|
77
77
|
dir: "./assets",
|
|
78
78
|
base: joinURL(args.publicUrl, "assets"),
|
|
79
79
|
},
|
|
80
|
-
{
|
|
81
|
-
name: "trpc-api",
|
|
82
|
-
type: "http",
|
|
83
|
-
base: "/trpc/",
|
|
84
|
-
handler: `${folder}/handler.trpc-api.ts`,
|
|
85
|
-
target: "server",
|
|
86
|
-
plugins: () => [
|
|
87
|
-
tsconfigPaths(),
|
|
88
|
-
envPlugin({
|
|
89
|
-
rootDir: args.rootDir,
|
|
90
|
-
console: log,
|
|
91
|
-
mode: args.mode,
|
|
92
|
-
publicUrl: args.publicUrl,
|
|
93
|
-
serverless: true,
|
|
94
|
-
target: "frontend",
|
|
95
|
-
}),
|
|
96
|
-
],
|
|
97
|
-
},
|
|
98
80
|
{
|
|
99
81
|
name: "data-api",
|
|
100
82
|
type: "http",
|
|
@@ -165,24 +147,24 @@ export function createVinxiApp(args) {
|
|
|
165
147
|
],
|
|
166
148
|
base: "/_admin",
|
|
167
149
|
},
|
|
168
|
-
...(args.rpcBases ?? []).map((base) => ({
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
})),
|
|
150
|
+
// ...((args.rpcBases ?? []).map((base) => ({
|
|
151
|
+
// name: "trpc" + base.replace(/^\//, "-"),
|
|
152
|
+
// type: "http",
|
|
153
|
+
// base: "/" + base.replace(/^\//, ""),
|
|
154
|
+
// handler: `${folder}/handler.trpc-api.ts`,
|
|
155
|
+
// target: "server",
|
|
156
|
+
// plugins: () => [
|
|
157
|
+
// tsconfigPaths(),
|
|
158
|
+
// envPlugin({
|
|
159
|
+
// rootDir: args.rootDir,
|
|
160
|
+
// console: log,
|
|
161
|
+
// mode: args.mode,
|
|
162
|
+
// publicUrl: args.publicUrl,
|
|
163
|
+
// serverless: true,
|
|
164
|
+
// target: "frontend",
|
|
165
|
+
// }),
|
|
166
|
+
// ],
|
|
167
|
+
// })) as RouterSchemaInput[]),
|
|
186
168
|
{
|
|
187
169
|
name: "ssr",
|
|
188
170
|
type: "http",
|
|
@@ -18,7 +18,7 @@ export function createVinxiCodegen(opts) {
|
|
|
18
18
|
if (opts.serverless) {
|
|
19
19
|
codegen.registerFile({
|
|
20
20
|
name: "context.ts",
|
|
21
|
-
generate: () => {
|
|
21
|
+
generate: async () => {
|
|
22
22
|
const args = {
|
|
23
23
|
dev: true,
|
|
24
24
|
origin: project.origin,
|
|
@@ -30,6 +30,7 @@ export function createVinxiCodegen(opts) {
|
|
|
30
30
|
{ prefix: "/wp-content/plugins", replace: project.config?.serverless.plugins === "proxy" },
|
|
31
31
|
],
|
|
32
32
|
},
|
|
33
|
+
rpcBases: (await project.serverRoutes.get()).bases ?? [],
|
|
33
34
|
};
|
|
34
35
|
return code /* tsx */ `
|
|
35
36
|
import { ServerContext } from "eddev/server"
|
|
@@ -248,56 +249,25 @@ export function createVinxiCodegen(opts) {
|
|
|
248
249
|
import "./manifest/styles.js"
|
|
249
250
|
import "./manifest/views.js"
|
|
250
251
|
import "./context.js"
|
|
251
|
-
|
|
252
|
+
import { handleRPC } from "./rpc.js"
|
|
252
253
|
import { proxyWpAdmin, ServerContext, renderPage } from "eddev/server"
|
|
253
254
|
import { eventHandler, getRequestURL } from "vinxi/http"
|
|
254
|
-
import { RouteData } from "eddev/routing"
|
|
255
255
|
|
|
256
256
|
export default eventHandler({
|
|
257
257
|
handler: async (event) => {
|
|
258
258
|
const serverContext = ServerContext.main
|
|
259
259
|
const url = getRequestURL(event)
|
|
260
260
|
|
|
261
|
+
const isRPC = serverContext.rpcBases.some((base) => url.pathname.startsWith(base))
|
|
262
|
+
if (isRPC) {
|
|
263
|
+
return handleRPC(event)
|
|
264
|
+
}
|
|
265
|
+
|
|
261
266
|
if (url.pathname.includes(".")) {
|
|
262
267
|
return proxyWpAdmin(event)
|
|
263
268
|
}
|
|
264
269
|
|
|
265
270
|
return renderPage({ pathname: url.pathname })
|
|
266
|
-
|
|
267
|
-
// try {
|
|
268
|
-
// const [{appData, trackers}, response] = await Promise.all([
|
|
269
|
-
// serverContext.fetchAppData(),
|
|
270
|
-
// serverContext.fetchRouteData({
|
|
271
|
-
// pathname: url.pathname,
|
|
272
|
-
// withAppData: false,
|
|
273
|
-
// headers: {},
|
|
274
|
-
// query: {},
|
|
275
|
-
// }),
|
|
276
|
-
// ])
|
|
277
|
-
|
|
278
|
-
// let data: RouteData
|
|
279
|
-
// try {
|
|
280
|
-
// data = await response.json()
|
|
281
|
-
// data.appData = appData
|
|
282
|
-
// data.trackers = trackers
|
|
283
|
-
// } catch (err) {
|
|
284
|
-
// data = {
|
|
285
|
-
// view: "_error",
|
|
286
|
-
// viewType: "react",
|
|
287
|
-
// viewData: {},
|
|
288
|
-
// appData: appData,
|
|
289
|
-
// }
|
|
290
|
-
// console.error(err)
|
|
291
|
-
// setResponseStatus(event, 500)
|
|
292
|
-
// }
|
|
293
|
-
// setResponseHeader(event, "Content-Type", "text/html; charset=utf-8")
|
|
294
|
-
// return renderPageToSSRStream(url.pathname, data)
|
|
295
|
-
// } catch (err) {
|
|
296
|
-
// console.error(err)
|
|
297
|
-
// setResponseStatus(event, 500)
|
|
298
|
-
// setResponseHeader(event, "Content-Type", "text/html; charset=utf-8")
|
|
299
|
-
// return '<!DOCTYPE html><html><head><title>500 Internal Server Error</title></head><body><h1>500 Internal Server Error</h1><p>"'+err.message+'"</p></body></html>'
|
|
300
|
-
// }
|
|
301
271
|
}
|
|
302
272
|
})
|
|
303
273
|
`,
|
|
@@ -491,55 +461,53 @@ export function createVinxiCodegen(opts) {
|
|
|
491
461
|
subscribe: project.serverRoutes.subscribe,
|
|
492
462
|
});
|
|
493
463
|
codegen.registerFile({
|
|
494
|
-
name: "
|
|
464
|
+
name: "rpc.ts",
|
|
495
465
|
generate: code /* tsx */ `
|
|
496
466
|
/// <reference types="vinxi/types/server" />
|
|
497
467
|
import "./context.js"
|
|
498
468
|
import { fetchRequestHandler } from "@trpc/server/adapters/fetch"
|
|
499
|
-
import { eventHandler, getWebRequest } from "vinxi/http"
|
|
500
|
-
import { createContext, router } from "./manifest/routes.ts"
|
|
501
469
|
import { parseURL, stringifyParsedURL } from "ufo"
|
|
470
|
+
import { EventHandlerRequest, getWebRequest, H3Event } from "vinxi/http"
|
|
471
|
+
import { createContext, router } from "./manifest/routes.ts"
|
|
502
472
|
|
|
503
|
-
export
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
return value
|
|
515
|
-
}
|
|
473
|
+
export function handleRPC(event: H3Event<EventHandlerRequest>) {
|
|
474
|
+
// Update URLs with dots, which tRPC prefers
|
|
475
|
+
const originalReq = getWebRequest(event)
|
|
476
|
+
const parsed = parseURL(originalReq.url)
|
|
477
|
+
parsed.pathname = "/" + parsed.pathname.replace(/(^\\/|\\/$)/g, "").replace(/\\//, ".")
|
|
478
|
+
const req = new Request(stringifyParsedURL(parsed), originalReq)
|
|
479
|
+
|
|
480
|
+
// Handle any early results which are Responses
|
|
481
|
+
function processEarlyResult(value: any): Response | undefined {
|
|
482
|
+
if (value instanceof Response) {
|
|
483
|
+
return value
|
|
516
484
|
}
|
|
485
|
+
}
|
|
517
486
|
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
})
|
|
538
|
-
if (sent) return
|
|
539
|
-
resolve(defaultResponse)
|
|
487
|
+
return new Promise(async (resolve) => {
|
|
488
|
+
let sent = false
|
|
489
|
+
const defaultResponse = await fetchRequestHandler({
|
|
490
|
+
endpoint: "/",
|
|
491
|
+
req: req,
|
|
492
|
+
router: router,
|
|
493
|
+
createContext,
|
|
494
|
+
onError: (err) => console.error(err),
|
|
495
|
+
batching: { enabled: false },
|
|
496
|
+
// If a Response object is returned by a route, it will be sent as the response
|
|
497
|
+
responseMeta(opts) {
|
|
498
|
+
const value = opts?.data?.[0]?.["result"]?.["data"]
|
|
499
|
+
const response = processEarlyResult(value)
|
|
500
|
+
if (response) {
|
|
501
|
+
sent = true
|
|
502
|
+
resolve(response)
|
|
503
|
+
}
|
|
504
|
+
return {}
|
|
505
|
+
},
|
|
540
506
|
})
|
|
541
|
-
|
|
542
|
-
|
|
507
|
+
if (sent) return
|
|
508
|
+
resolve(defaultResponse)
|
|
509
|
+
})
|
|
510
|
+
}
|
|
543
511
|
`,
|
|
544
512
|
});
|
|
545
513
|
}
|