@faapi/faapi 4.0.0 → 4.2.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 +197 -58
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.js +221 -85
- package/dist/index.js.map +1 -1
- package/dist/testing.js +42 -15
- package/dist/testing.js.map +1 -1
- package/package.json +1 -1
package/dist/testing.js
CHANGED
|
@@ -2842,6 +2842,15 @@ function toStrippedProdImportPath(sourceFile, rootDir) {
|
|
|
2842
2842
|
if (!rel.startsWith(".")) rel = "./" + rel;
|
|
2843
2843
|
return toProdExtension(rel);
|
|
2844
2844
|
}
|
|
2845
|
+
function toProdImportFromImporter(importer, rootDir, relFromDist) {
|
|
2846
|
+
const importerRel = path8.relative(toRealPath(path8.resolve(rootDir)), toRealPath(importer)).split(path8.sep).join("/");
|
|
2847
|
+
const importerProdDir = path8.posix.dirname(toProdExtension(importerRel));
|
|
2848
|
+
if (importerProdDir === ".") return relFromDist;
|
|
2849
|
+
const target = relFromDist.replace(/^\.\//, "");
|
|
2850
|
+
let rel = path8.posix.relative(importerProdDir, target);
|
|
2851
|
+
if (!rel.startsWith(".")) rel = "./" + rel;
|
|
2852
|
+
return rel;
|
|
2853
|
+
}
|
|
2845
2854
|
var PROD_EXTS = [".js", ".mjs", ".cjs"];
|
|
2846
2855
|
var SOURCE_EXTS = [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"];
|
|
2847
2856
|
var INDEX_EXTS = [
|
|
@@ -2899,9 +2908,10 @@ function createAliasPlugin(config, options) {
|
|
|
2899
2908
|
}
|
|
2900
2909
|
if (appDirAbs && importerOutsideAppDir && isInsideDir(resolved, appDirAbs)) {
|
|
2901
2910
|
modified = true;
|
|
2902
|
-
return `${prefix}${quote}${
|
|
2903
|
-
|
|
2904
|
-
options.rootDir
|
|
2911
|
+
return `${prefix}${quote}${toProdImportFromImporter(
|
|
2912
|
+
importer,
|
|
2913
|
+
options.rootDir,
|
|
2914
|
+
toStrippedProdImportPath(resolved, options.rootDir)
|
|
2905
2915
|
)}${quote}`;
|
|
2906
2916
|
}
|
|
2907
2917
|
modified = true;
|
|
@@ -2916,9 +2926,10 @@ function createAliasPlugin(config, options) {
|
|
|
2916
2926
|
if (fs6.existsSync(file)) {
|
|
2917
2927
|
modified = true;
|
|
2918
2928
|
if (appDirAbs && importerOutsideAppDir && isInsideDir(file, appDirAbs)) {
|
|
2919
|
-
return `${prefix}${quote}${
|
|
2920
|
-
|
|
2921
|
-
options.rootDir
|
|
2929
|
+
return `${prefix}${quote}${toProdImportFromImporter(
|
|
2930
|
+
importer,
|
|
2931
|
+
options.rootDir,
|
|
2932
|
+
toStrippedProdImportPath(file, options.rootDir)
|
|
2922
2933
|
)}${quote}`;
|
|
2923
2934
|
}
|
|
2924
2935
|
return `${prefix}${quote}${toProdImportPath(file, importer)}${quote}`;
|
|
@@ -2929,9 +2940,10 @@ function createAliasPlugin(config, options) {
|
|
|
2929
2940
|
if (fs6.existsSync(file)) {
|
|
2930
2941
|
modified = true;
|
|
2931
2942
|
if (appDirAbs && importerOutsideAppDir && isInsideDir(file, appDirAbs)) {
|
|
2932
|
-
return `${prefix}${quote}${
|
|
2933
|
-
|
|
2934
|
-
options.rootDir
|
|
2943
|
+
return `${prefix}${quote}${toProdImportFromImporter(
|
|
2944
|
+
importer,
|
|
2945
|
+
options.rootDir,
|
|
2946
|
+
toStrippedProdImportPath(file, options.rootDir)
|
|
2935
2947
|
)}${quote}`;
|
|
2936
2948
|
}
|
|
2937
2949
|
return `${prefix}${quote}${toProdImportPath(file, importer)}${quote}`;
|
|
@@ -4235,7 +4247,7 @@ function attachWebSocket(options) {
|
|
|
4235
4247
|
|
|
4236
4248
|
// src/server/createServer.ts
|
|
4237
4249
|
var DEFAULT_BODY_LIMIT = 10 * 1024 * 1024;
|
|
4238
|
-
function toWebRequest(req, bodyLimit = DEFAULT_BODY_LIMIT) {
|
|
4250
|
+
function toWebRequest(req, bodyLimit = DEFAULT_BODY_LIMIT, requestSignal) {
|
|
4239
4251
|
const forwardedProto = req.headers["x-forwarded-proto"];
|
|
4240
4252
|
const protocol = Array.isArray(forwardedProto) ? forwardedProto[0]?.split(",")[0]?.trim() ?? "http" : forwardedProto?.split(",")[0]?.trim() ?? "http";
|
|
4241
4253
|
const host = req.headers.host ?? "localhost";
|
|
@@ -4243,7 +4255,10 @@ function toWebRequest(req, bodyLimit = DEFAULT_BODY_LIMIT) {
|
|
|
4243
4255
|
const headers = nodeHttpToWebHeaders(req);
|
|
4244
4256
|
const method = req.method ?? "GET";
|
|
4245
4257
|
if (method === "GET" || method === "HEAD") {
|
|
4246
|
-
return {
|
|
4258
|
+
return {
|
|
4259
|
+
request: new Request(url.toString(), { method, headers, signal: requestSignal }),
|
|
4260
|
+
url
|
|
4261
|
+
};
|
|
4247
4262
|
}
|
|
4248
4263
|
const contentLength = req.headers["content-length"];
|
|
4249
4264
|
if (contentLength !== void 0) {
|
|
@@ -4259,7 +4274,8 @@ function toWebRequest(req, bodyLimit = DEFAULT_BODY_LIMIT) {
|
|
|
4259
4274
|
method,
|
|
4260
4275
|
headers,
|
|
4261
4276
|
body: limitedStream,
|
|
4262
|
-
duplex: "half"
|
|
4277
|
+
duplex: "half",
|
|
4278
|
+
signal: requestSignal
|
|
4263
4279
|
}),
|
|
4264
4280
|
url
|
|
4265
4281
|
};
|
|
@@ -4398,8 +4414,8 @@ function createServer(options) {
|
|
|
4398
4414
|
});
|
|
4399
4415
|
return { server, routesRef };
|
|
4400
4416
|
}
|
|
4401
|
-
function prepareRequest(req, config, bodyLimit, trustedProxy, registries) {
|
|
4402
|
-
const { request, url } = toWebRequest(req, bodyLimit);
|
|
4417
|
+
function prepareRequest(req, config, bodyLimit, trustedProxy, registries, requestSignal) {
|
|
4418
|
+
const { request, url } = toWebRequest(req, bodyLimit, requestSignal);
|
|
4403
4419
|
const method = request.method.toUpperCase();
|
|
4404
4420
|
const urlPath = url.pathname;
|
|
4405
4421
|
const ctx = createContextFromUrl(
|
|
@@ -4485,8 +4501,19 @@ async function sendErrorResponse(err, meta, res, onError, ctx) {
|
|
|
4485
4501
|
async function handleRequest(routes, rootDir, dist, req, res, outerMiddlewares, onError, config, globalInjectors, bodyLimit, trustedProxy, registries) {
|
|
4486
4502
|
let meta = { headers: {}, setCookies: [] };
|
|
4487
4503
|
let ctx;
|
|
4504
|
+
const abortController = new AbortController();
|
|
4505
|
+
res.on("close", () => {
|
|
4506
|
+
if (!res.writableEnded) abortController.abort();
|
|
4507
|
+
});
|
|
4488
4508
|
try {
|
|
4489
|
-
const prepared = prepareRequest(
|
|
4509
|
+
const prepared = prepareRequest(
|
|
4510
|
+
req,
|
|
4511
|
+
config,
|
|
4512
|
+
bodyLimit,
|
|
4513
|
+
trustedProxy,
|
|
4514
|
+
registries,
|
|
4515
|
+
abortController.signal
|
|
4516
|
+
);
|
|
4490
4517
|
ctx = prepared.ctx;
|
|
4491
4518
|
meta = prepared.meta;
|
|
4492
4519
|
const { request, url, method, urlPath } = prepared;
|