@midwayjs/mock 3.13.6 → 3.13.8
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/creator.js +32 -20
- package/package.json +4 -4
package/dist/creator.js
CHANGED
|
@@ -314,27 +314,39 @@ async function createFunctionApp(baseDir, options = {}, customFrameworkModule) {
|
|
|
314
314
|
var _a;
|
|
315
315
|
return ((_a = options.starter) === null || _a === void 0 ? void 0 : _a.createDefaultMockContext()) || {};
|
|
316
316
|
};
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
res.statusCode
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
317
|
+
try {
|
|
318
|
+
const ctx = await framework.wrapHttpRequest(req);
|
|
319
|
+
// create event and invoke
|
|
320
|
+
const result = await framework.invokeTriggerFunction(ctx, url.pathname, {
|
|
321
|
+
isHttpFunction: true,
|
|
322
|
+
});
|
|
323
|
+
const { statusCode, headers, body, isBase64Encoded } = result;
|
|
324
|
+
if (res.headersSent) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
for (const key in headers) {
|
|
328
|
+
res.setHeader(key, headers[key]);
|
|
329
|
+
}
|
|
330
|
+
if (res.statusCode !== statusCode) {
|
|
331
|
+
res.statusCode = statusCode;
|
|
332
|
+
}
|
|
333
|
+
// http trigger only support `Buffer` or a `string` or a `stream.Readable`
|
|
334
|
+
if (isBase64Encoded && typeof body === 'string') {
|
|
335
|
+
res.end(Buffer.from(body, 'base64'));
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
res.end(body);
|
|
339
|
+
}
|
|
335
340
|
}
|
|
336
|
-
|
|
337
|
-
|
|
341
|
+
catch (err) {
|
|
342
|
+
if (/favicon\.ico not found/.test(err.message)) {
|
|
343
|
+
res.statusCode = 404;
|
|
344
|
+
res.end();
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
console.error(err);
|
|
348
|
+
res.statusCode = err.status || 500;
|
|
349
|
+
res.end(err.message);
|
|
338
350
|
}
|
|
339
351
|
};
|
|
340
352
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/mock",
|
|
3
|
-
"version": "3.13.
|
|
3
|
+
"version": "3.13.8",
|
|
4
4
|
"description": "create your test app from midway framework",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@midwayjs/core": "^3.13.
|
|
32
|
+
"@midwayjs/core": "^3.13.7",
|
|
33
33
|
"@midwayjs/logger": "^3.0.0",
|
|
34
34
|
"@types/amqplib": "0.10.4",
|
|
35
35
|
"amqplib": "0.10.3",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"ws": "8.14.2"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@midwayjs/async-hooks-context-manager": "^3.13.
|
|
42
|
+
"@midwayjs/async-hooks-context-manager": "^3.13.7",
|
|
43
43
|
"@types/superagent": "4.1.14",
|
|
44
44
|
"@types/supertest": "2.0.16",
|
|
45
45
|
"js-yaml": "4.1.0",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"type": "git",
|
|
52
52
|
"url": "https://github.com/midwayjs/midway.git"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "a0b8dc4d1627a3108f9f3c1f77edc9d2e7b328dd"
|
|
55
55
|
}
|