@shuvi/platform-web 1.0.32 → 1.0.33
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.
|
@@ -15,7 +15,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.middleware = void 0;
|
|
16
16
|
const router_1 = require("@shuvi/router");
|
|
17
17
|
const resources_1 = __importDefault(require("@shuvi/service/lib/resources"));
|
|
18
|
+
const trace_1 = require("@shuvi/shared/constants/trace");
|
|
18
19
|
const apiRouteHandler_1 = require("./apiRouteHandler");
|
|
20
|
+
const { SHUVI_SERVER_RUN_API_MIDDLEWARE } = trace_1.SERVER_REQUEST.events;
|
|
19
21
|
function middleware(_ctx) {
|
|
20
22
|
return function (req, res, next) {
|
|
21
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -30,13 +32,24 @@ function middleware(_ctx) {
|
|
|
30
32
|
}
|
|
31
33
|
}
|
|
32
34
|
if (tempApiModule) {
|
|
35
|
+
const { serverRequestTrace } = _ctx.traces;
|
|
36
|
+
const runApiMiddlewareTrace = serverRequestTrace.traceChild(SHUVI_SERVER_RUN_API_MIDDLEWARE.name);
|
|
33
37
|
try {
|
|
34
38
|
const { config, default: resolver } = tempApiModule;
|
|
35
39
|
yield (0, apiRouteHandler_1.apiRouteHandler)(req, res, resolver, (config === null || config === void 0 ? void 0 : config.api) || { bodyParser: true });
|
|
36
40
|
}
|
|
37
41
|
catch (error) {
|
|
42
|
+
runApiMiddlewareTrace.setAttributes({
|
|
43
|
+
[SHUVI_SERVER_RUN_API_MIDDLEWARE.attrs.error.name]: true,
|
|
44
|
+
[SHUVI_SERVER_RUN_API_MIDDLEWARE.attrs.statusCode.name]: res.statusCode
|
|
45
|
+
});
|
|
38
46
|
next(error);
|
|
39
47
|
}
|
|
48
|
+
runApiMiddlewareTrace.setAttributes({
|
|
49
|
+
[SHUVI_SERVER_RUN_API_MIDDLEWARE.attrs.error.name]: false,
|
|
50
|
+
[SHUVI_SERVER_RUN_API_MIDDLEWARE.attrs.statusCode.name]: res.statusCode
|
|
51
|
+
});
|
|
52
|
+
runApiMiddlewareTrace.stop();
|
|
40
53
|
}
|
|
41
54
|
else {
|
|
42
55
|
next();
|
|
@@ -15,30 +15,65 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.middleware = void 0;
|
|
16
16
|
const router_1 = require("@shuvi/router");
|
|
17
17
|
const resources_1 = __importDefault(require("@shuvi/service/lib/resources"));
|
|
18
|
+
const trace_1 = require("@shuvi/shared/constants/trace");
|
|
19
|
+
const { SHUVI_SERVER_RUN_MIDDLEWARE_ROUTES } = trace_1.SERVER_REQUEST.events;
|
|
18
20
|
function middleware(_api) {
|
|
21
|
+
const { serverCreateAppTrace } = _api.traces;
|
|
19
22
|
return function (req, res, next) {
|
|
20
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
const middlewareRoutesTrace = serverCreateAppTrace.traceChild(SHUVI_SERVER_RUN_MIDDLEWARE_ROUTES.name);
|
|
25
|
+
try {
|
|
26
|
+
const { middlewareRoutes = [] } = resources_1.default.server;
|
|
27
|
+
// match path for get middlewares
|
|
28
|
+
let middlewares = [];
|
|
29
|
+
for (let i = 0; i < middlewareRoutes.length; i++) {
|
|
30
|
+
const middlewareRoute = middlewareRoutes[i];
|
|
31
|
+
const match = (0, router_1.matchPathname)(middlewareRoute.path, req.pathname);
|
|
32
|
+
if (match) {
|
|
33
|
+
req.params = match.params;
|
|
34
|
+
middlewares.push(middlewareRoutes[i].middleware.default);
|
|
35
|
+
}
|
|
30
36
|
}
|
|
37
|
+
// run middlewares
|
|
38
|
+
let i = 0;
|
|
39
|
+
const runNext = () => runMiddleware(middlewares[++i]);
|
|
40
|
+
const runMiddleware = (middleware) => __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
if (i === middlewares.length) {
|
|
42
|
+
/** Most request should end here */
|
|
43
|
+
middlewareRoutesTrace.setAttributes({
|
|
44
|
+
[SHUVI_SERVER_RUN_MIDDLEWARE_ROUTES.attrs.error.name]: false,
|
|
45
|
+
[SHUVI_SERVER_RUN_MIDDLEWARE_ROUTES.attrs.statusCode.name]: res.statusCode,
|
|
46
|
+
[SHUVI_SERVER_RUN_MIDDLEWARE_ROUTES.attrs.headersSent.name]: res.headersSent
|
|
47
|
+
});
|
|
48
|
+
middlewareRoutesTrace.stop();
|
|
49
|
+
return next();
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
yield middleware(req, res, runNext);
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
/** Catch error from single middleware */
|
|
56
|
+
middlewareRoutesTrace.setAttributes({
|
|
57
|
+
[SHUVI_SERVER_RUN_MIDDLEWARE_ROUTES.attrs.error.name]: true,
|
|
58
|
+
[SHUVI_SERVER_RUN_MIDDLEWARE_ROUTES.attrs.statusCode.name]: 500,
|
|
59
|
+
[SHUVI_SERVER_RUN_MIDDLEWARE_ROUTES.attrs.headersSent.name]: res.headersSent
|
|
60
|
+
});
|
|
61
|
+
middlewareRoutesTrace.stop();
|
|
62
|
+
return next(err);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return yield runMiddleware(middlewares[i]);
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
/** Catch error from the whole function */
|
|
69
|
+
middlewareRoutesTrace.setAttributes({
|
|
70
|
+
[SHUVI_SERVER_RUN_MIDDLEWARE_ROUTES.attrs.error.name]: true,
|
|
71
|
+
[SHUVI_SERVER_RUN_MIDDLEWARE_ROUTES.attrs.statusCode.name]: 500,
|
|
72
|
+
[SHUVI_SERVER_RUN_MIDDLEWARE_ROUTES.attrs.headersSent.name]: res.headersSent
|
|
73
|
+
});
|
|
74
|
+
middlewareRoutesTrace.stop();
|
|
75
|
+
return next(err);
|
|
31
76
|
}
|
|
32
|
-
// run middlewares
|
|
33
|
-
let i = 0;
|
|
34
|
-
const runNext = () => runMiddleware(middlewares[++i]);
|
|
35
|
-
const runMiddleware = (middleware) => __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
if (i === middlewares.length) {
|
|
37
|
-
return next();
|
|
38
|
-
}
|
|
39
|
-
yield middleware(req, res, runNext);
|
|
40
|
-
});
|
|
41
|
-
return yield runMiddleware(middlewares[i]);
|
|
42
77
|
});
|
|
43
78
|
};
|
|
44
79
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shuvi/platform-web",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.33",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/shuvijs/shuvi.git",
|
|
@@ -72,15 +72,15 @@
|
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
74
|
"@next/react-refresh-utils": "12.1.6",
|
|
75
|
-
"@shuvi/error-overlay": "1.0.
|
|
76
|
-
"@shuvi/hook": "1.0.
|
|
77
|
-
"@shuvi/platform-shared": "1.0.
|
|
78
|
-
"@shuvi/router": "1.0.
|
|
79
|
-
"@shuvi/router-react": "1.0.
|
|
80
|
-
"@shuvi/runtime": "1.0.
|
|
81
|
-
"@shuvi/shared": "1.0.
|
|
82
|
-
"@shuvi/toolpack": "1.0.
|
|
83
|
-
"@shuvi/utils": "1.0.
|
|
75
|
+
"@shuvi/error-overlay": "1.0.33",
|
|
76
|
+
"@shuvi/hook": "1.0.33",
|
|
77
|
+
"@shuvi/platform-shared": "1.0.33",
|
|
78
|
+
"@shuvi/router": "1.0.33",
|
|
79
|
+
"@shuvi/router-react": "1.0.33",
|
|
80
|
+
"@shuvi/runtime": "1.0.33",
|
|
81
|
+
"@shuvi/shared": "1.0.33",
|
|
82
|
+
"@shuvi/toolpack": "1.0.33",
|
|
83
|
+
"@shuvi/utils": "1.0.33",
|
|
84
84
|
"content-type": "1.0.4",
|
|
85
85
|
"core-js": "3.6.5",
|
|
86
86
|
"doura": "0.0.11",
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
"whatwg-fetch": "3.0.0"
|
|
99
99
|
},
|
|
100
100
|
"peerDependencies": {
|
|
101
|
-
"@shuvi/service": "1.0.
|
|
101
|
+
"@shuvi/service": "1.0.33"
|
|
102
102
|
},
|
|
103
103
|
"devDependencies": {
|
|
104
104
|
"@shuvi/service": "workspace:*",
|