silgi 0.37.10 → 0.37.12
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/index.mjs +1 -1
- package/dist/core/index.mjs +20 -12
- package/dist/runtime/internal/nitro.mjs +8 -41
- package/dist/types/index.d.mts +2 -2
- package/package.json +1 -1
package/dist/cli/index.mjs
CHANGED
package/dist/core/index.mjs
CHANGED
|
@@ -811,6 +811,14 @@ function substitutePathParams(path, pathParams) {
|
|
|
811
811
|
return `:${key}`;
|
|
812
812
|
});
|
|
813
813
|
}
|
|
814
|
+
function withDuplexIfBody(options) {
|
|
815
|
+
if (!options)
|
|
816
|
+
return options;
|
|
817
|
+
if (options.body && !("duplex" in options)) {
|
|
818
|
+
return { ...options, duplex: "half" };
|
|
819
|
+
}
|
|
820
|
+
return options;
|
|
821
|
+
}
|
|
814
822
|
function createSilgiCore(event) {
|
|
815
823
|
return {
|
|
816
824
|
resolve: async (path, method, context) => {
|
|
@@ -821,7 +829,7 @@ function createSilgiCore(event) {
|
|
|
821
829
|
const routeStr = substitutePathParams(String(path), context?.pathParams);
|
|
822
830
|
const methodStr = String(method);
|
|
823
831
|
const match = findRoute(silgiCtx.router, methodStr, routeStr);
|
|
824
|
-
return match?.data?.
|
|
832
|
+
return match?.data?.service;
|
|
825
833
|
}
|
|
826
834
|
};
|
|
827
835
|
}
|
|
@@ -836,20 +844,20 @@ async function silgiFetch(_request, options, context) {
|
|
|
836
844
|
const proto = getHeader("X-Forwarded-Proto", options?.headers) === "https" ? "https" : "http";
|
|
837
845
|
url = `${proto}://${host}${url}`;
|
|
838
846
|
}
|
|
839
|
-
request = new Request(url, options);
|
|
847
|
+
request = new Request(url, withDuplexIfBody(options));
|
|
840
848
|
} else if (options || _request instanceof URL) {
|
|
841
|
-
request = new Request(_request, options);
|
|
849
|
+
request = new Request(_request, withDuplexIfBody(options));
|
|
842
850
|
} else {
|
|
843
851
|
request = _request;
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
}
|
|
852
|
+
}
|
|
853
|
+
const silgiURL = getUrlPrefix(request.url, request.method);
|
|
854
|
+
const match = findRoute(silgiCtx.router, request.method, silgiURL.path);
|
|
855
|
+
if (!match) {
|
|
856
|
+
throw createError({
|
|
857
|
+
message: "Route not found",
|
|
858
|
+
statusCode: 404,
|
|
859
|
+
statusMessage: "Route not found"
|
|
860
|
+
});
|
|
853
861
|
}
|
|
854
862
|
const silgiEvent = new _SilgiEvent(request, context);
|
|
855
863
|
let handlerRes;
|
|
@@ -3,8 +3,6 @@ import {
|
|
|
3
3
|
getRequestWebStream
|
|
4
4
|
} from "h3";
|
|
5
5
|
import {
|
|
6
|
-
createError,
|
|
7
|
-
getUrlPrefix,
|
|
8
6
|
silgiFetch,
|
|
9
7
|
useSilgi
|
|
10
8
|
} from "silgi";
|
|
@@ -16,46 +14,15 @@ export async function addNitroApp(silgiContext = useSilgi()) {
|
|
|
16
14
|
const prefixs = silgiContext.routerPrefixs;
|
|
17
15
|
for (const prefix of prefixs) {
|
|
18
16
|
nitro.router.use(`${prefix}/**`, defineEventHandler(async (event) => {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
event.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
body: event.method.toUpperCase() === "GET" ? void 0 : getRequestWebStream(event),
|
|
26
|
-
headers: event.headers
|
|
27
|
-
}
|
|
28
|
-
);
|
|
29
|
-
if (!resolvedRoute.ok) {
|
|
30
|
-
await silgiContext.callHook("fetch:error", {
|
|
31
|
-
error: new Error(resolvedRoute.statusText),
|
|
32
|
-
url: silgiURL
|
|
33
|
-
});
|
|
34
|
-
silgiContext.captureError(
|
|
35
|
-
silgiContext,
|
|
36
|
-
createError({
|
|
37
|
-
message: resolvedRoute.statusText,
|
|
38
|
-
statusCode: resolvedRoute.status,
|
|
39
|
-
statusMessage: resolvedRoute.statusText
|
|
40
|
-
}),
|
|
41
|
-
{
|
|
42
|
-
url: silgiURL,
|
|
43
|
-
tags: ["execute"]
|
|
44
|
-
}
|
|
45
|
-
);
|
|
46
|
-
throw createError({
|
|
47
|
-
statusCode: resolvedRoute.status,
|
|
48
|
-
statusMessage: resolvedRoute.statusText
|
|
49
|
-
});
|
|
17
|
+
const resolvedRoute = await silgiFetch(
|
|
18
|
+
event.path,
|
|
19
|
+
{
|
|
20
|
+
method: event.method.toUpperCase(),
|
|
21
|
+
body: event.method.toUpperCase() === "GET" ? void 0 : getRequestWebStream(event),
|
|
22
|
+
headers: event.headers
|
|
50
23
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
throw createError({
|
|
54
|
-
statusCode: 500,
|
|
55
|
-
message: "Internal Server Error",
|
|
56
|
-
cause: err
|
|
57
|
-
});
|
|
58
|
-
}
|
|
24
|
+
);
|
|
25
|
+
return resolvedRoute;
|
|
59
26
|
}));
|
|
60
27
|
}
|
|
61
28
|
}
|
package/dist/types/index.d.mts
CHANGED
|
@@ -821,12 +821,12 @@ type ModuleHookContext = Readonly<{
|
|
|
821
821
|
url: SilgiURL;
|
|
822
822
|
input?: unknown;
|
|
823
823
|
result?: unknown;
|
|
824
|
-
route
|
|
824
|
+
route?: SilgiRoute;
|
|
825
825
|
error?: Error;
|
|
826
826
|
success?: boolean;
|
|
827
827
|
cached?: boolean;
|
|
828
828
|
}> & {
|
|
829
|
-
hookContext
|
|
829
|
+
hookContext?: {
|
|
830
830
|
earlyReturnValue: any | false;
|
|
831
831
|
};
|
|
832
832
|
};
|