@rpcbase/client 0.233.0 → 0.235.0
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/package.json
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import assert from "assert"
|
|
3
|
-
|
|
4
2
|
import { Application, IRouter, Request, Response } from "express"
|
|
5
3
|
|
|
6
4
|
// import { Ctx } from "@rpcbase/api"
|
|
@@ -80,7 +78,9 @@ export const getServerApiClient = async(app: Application) => {
|
|
|
80
78
|
return
|
|
81
79
|
}
|
|
82
80
|
|
|
83
|
-
|
|
81
|
+
if (layer.route.stack.length !== 1) {
|
|
82
|
+
throw new Error(`expected only one handler per route for route: ${layer.route.path}`);
|
|
83
|
+
}
|
|
84
84
|
|
|
85
85
|
await runHandler(layer.route.stack[0].handle)
|
|
86
86
|
|
|
@@ -111,7 +111,9 @@ export const getServerApiClient = async(app: Application) => {
|
|
|
111
111
|
payload: Record<string, unknown>,
|
|
112
112
|
ctx?: Ctx,
|
|
113
113
|
): Promise<TResponse> => {
|
|
114
|
-
|
|
114
|
+
if (!ctx) {
|
|
115
|
+
throw new Error("Context must be provided in SSR mode")
|
|
116
|
+
}
|
|
115
117
|
|
|
116
118
|
ctx.req.body = payload
|
|
117
119
|
return callRoute<TResponse>(app, method, path, ctx.req, ctx.res)
|
package/src/apiClient/index.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import assert from "assert"
|
|
2
|
-
|
|
3
1
|
import type { Application } from "express"
|
|
4
2
|
|
|
5
3
|
// import { Ctx } from "@rpcbase/api"
|
|
@@ -30,7 +28,9 @@ let apiClient: ApiClient
|
|
|
30
28
|
export const initApiClient = async (args?: ServerArgs) => {
|
|
31
29
|
// @ts-ignore
|
|
32
30
|
if (import.meta.env.SSR) {
|
|
33
|
-
|
|
31
|
+
if (!args) {
|
|
32
|
+
throw new Error("Server args must be provided in SSR mode")
|
|
33
|
+
}
|
|
34
34
|
|
|
35
35
|
const { getServerApiClient } = await import("./getServerApiClient")
|
|
36
36
|
|