@faapi/faapi 4.0.0 → 4.1.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/README.md +5 -0
- package/dist/cli/index.js +21 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/index.js +21 -6
- package/dist/index.js.map +1 -1
- package/dist/testing.js +21 -6
- package/dist/testing.js.map +1 -1
- package/package.json +1 -1
package/dist/testing.js
CHANGED
|
@@ -4235,7 +4235,7 @@ function attachWebSocket(options) {
|
|
|
4235
4235
|
|
|
4236
4236
|
// src/server/createServer.ts
|
|
4237
4237
|
var DEFAULT_BODY_LIMIT = 10 * 1024 * 1024;
|
|
4238
|
-
function toWebRequest(req, bodyLimit = DEFAULT_BODY_LIMIT) {
|
|
4238
|
+
function toWebRequest(req, bodyLimit = DEFAULT_BODY_LIMIT, requestSignal) {
|
|
4239
4239
|
const forwardedProto = req.headers["x-forwarded-proto"];
|
|
4240
4240
|
const protocol = Array.isArray(forwardedProto) ? forwardedProto[0]?.split(",")[0]?.trim() ?? "http" : forwardedProto?.split(",")[0]?.trim() ?? "http";
|
|
4241
4241
|
const host = req.headers.host ?? "localhost";
|
|
@@ -4243,7 +4243,10 @@ function toWebRequest(req, bodyLimit = DEFAULT_BODY_LIMIT) {
|
|
|
4243
4243
|
const headers = nodeHttpToWebHeaders(req);
|
|
4244
4244
|
const method = req.method ?? "GET";
|
|
4245
4245
|
if (method === "GET" || method === "HEAD") {
|
|
4246
|
-
return {
|
|
4246
|
+
return {
|
|
4247
|
+
request: new Request(url.toString(), { method, headers, signal: requestSignal }),
|
|
4248
|
+
url
|
|
4249
|
+
};
|
|
4247
4250
|
}
|
|
4248
4251
|
const contentLength = req.headers["content-length"];
|
|
4249
4252
|
if (contentLength !== void 0) {
|
|
@@ -4259,7 +4262,8 @@ function toWebRequest(req, bodyLimit = DEFAULT_BODY_LIMIT) {
|
|
|
4259
4262
|
method,
|
|
4260
4263
|
headers,
|
|
4261
4264
|
body: limitedStream,
|
|
4262
|
-
duplex: "half"
|
|
4265
|
+
duplex: "half",
|
|
4266
|
+
signal: requestSignal
|
|
4263
4267
|
}),
|
|
4264
4268
|
url
|
|
4265
4269
|
};
|
|
@@ -4398,8 +4402,8 @@ function createServer(options) {
|
|
|
4398
4402
|
});
|
|
4399
4403
|
return { server, routesRef };
|
|
4400
4404
|
}
|
|
4401
|
-
function prepareRequest(req, config, bodyLimit, trustedProxy, registries) {
|
|
4402
|
-
const { request, url } = toWebRequest(req, bodyLimit);
|
|
4405
|
+
function prepareRequest(req, config, bodyLimit, trustedProxy, registries, requestSignal) {
|
|
4406
|
+
const { request, url } = toWebRequest(req, bodyLimit, requestSignal);
|
|
4403
4407
|
const method = request.method.toUpperCase();
|
|
4404
4408
|
const urlPath = url.pathname;
|
|
4405
4409
|
const ctx = createContextFromUrl(
|
|
@@ -4485,8 +4489,19 @@ async function sendErrorResponse(err, meta, res, onError, ctx) {
|
|
|
4485
4489
|
async function handleRequest(routes, rootDir, dist, req, res, outerMiddlewares, onError, config, globalInjectors, bodyLimit, trustedProxy, registries) {
|
|
4486
4490
|
let meta = { headers: {}, setCookies: [] };
|
|
4487
4491
|
let ctx;
|
|
4492
|
+
const abortController = new AbortController();
|
|
4493
|
+
res.on("close", () => {
|
|
4494
|
+
if (!res.writableEnded) abortController.abort();
|
|
4495
|
+
});
|
|
4488
4496
|
try {
|
|
4489
|
-
const prepared = prepareRequest(
|
|
4497
|
+
const prepared = prepareRequest(
|
|
4498
|
+
req,
|
|
4499
|
+
config,
|
|
4500
|
+
bodyLimit,
|
|
4501
|
+
trustedProxy,
|
|
4502
|
+
registries,
|
|
4503
|
+
abortController.signal
|
|
4504
|
+
);
|
|
4490
4505
|
ctx = prepared.ctx;
|
|
4491
4506
|
meta = prepared.meta;
|
|
4492
4507
|
const { request, url, method, urlPath } = prepared;
|