@shuvi/platform-web 1.0.31 → 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 { middlewareRoutes = [] } = resources_1.default.server;
22
- // match path for get middlewares
23
- let middlewares = [];
24
- for (let i = 0; i < middlewareRoutes.length; i++) {
25
- const middlewareRoute = middlewareRoutes[i];
26
- const match = (0, router_1.matchPathname)(middlewareRoute.path, req.pathname);
27
- if (match) {
28
- req.params = match.params;
29
- middlewares.push(middlewareRoutes[i].middleware.default);
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/lib/node/index.js CHANGED
@@ -22,13 +22,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
22
22
  step((generator = generator.apply(thisArg, _arguments || [])).next());
23
23
  });
24
24
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
25
  Object.defineProperty(exports, "__esModule", { value: true });
29
26
  const node_1 = require("@shuvi/platform-shared/node");
30
- const trace_1 = __importDefault(require("./trace"));
31
- const external_internal_libs_1 = __importDefault(require("./external-internal-libs"));
32
27
  const features_1 = require("./features");
33
28
  const paths_1 = require("./paths");
34
29
  __exportStar(require("../shared"), exports);
@@ -43,8 +38,6 @@ const platform = ({ framework = 'react' } = {}) => (platformContext) => __awaite
43
38
  (0, paths_1.resolvePkgFile)('shuvi-image.d.ts')
44
39
  ],
45
40
  plugins: [
46
- external_internal_libs_1.default,
47
- trace_1.default,
48
41
  ...node_1.SharedPlugins,
49
42
  ...(0, features_1.getPlugins)(platformContext),
50
43
  ...platformFrameworkContent.plugins
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuvi/platform-web",
3
- "version": "1.0.31",
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.31",
76
- "@shuvi/hook": "1.0.31",
77
- "@shuvi/platform-shared": "1.0.31",
78
- "@shuvi/router": "1.0.31",
79
- "@shuvi/router-react": "1.0.31",
80
- "@shuvi/runtime": "1.0.31",
81
- "@shuvi/shared": "1.0.31",
82
- "@shuvi/toolpack": "1.0.31",
83
- "@shuvi/utils": "1.0.31",
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.31"
101
+ "@shuvi/service": "1.0.33"
102
102
  },
103
103
  "devDependencies": {
104
104
  "@shuvi/service": "workspace:*",
@@ -1,4 +0,0 @@
1
- declare const _default: {
2
- core: import("@shuvi/hook").IPluginInstance<import("@shuvi/service/lib/core/plugin").PluginHooks, import("@shuvi/service").IPluginContext>;
3
- };
4
- export default _default;
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const service_1 = require("@shuvi/service");
4
- const shared_1 = require("../shared");
5
- const paths_1 = require("./paths");
6
- const configWebpack = (config, { name, helpers }) => {
7
- if (name === shared_1.BUNDLER_TARGET_SERVER) {
8
- helpers.addExternals(config, ({ request }, next) => {
9
- if (/@shuvi[/\\](hook$|router$|utils)/.test(request)) {
10
- return next(null, (0, paths_1.resolveDep)(request));
11
- }
12
- else {
13
- return next(null, 'next');
14
- }
15
- });
16
- }
17
- return config;
18
- };
19
- exports.default = {
20
- core: (0, service_1.createPlugin)({
21
- configWebpack
22
- })
23
- };
@@ -1,4 +0,0 @@
1
- declare const _default: {
2
- core: import("@shuvi/hook").IPluginInstance<import("@shuvi/service/lib/core/plugin").PluginHooks, import("@shuvi/service").IPluginContext>;
3
- };
4
- export default _default;
package/lib/node/trace.js DELETED
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const service_1 = require("@shuvi/service");
4
- const shared_1 = require("../shared");
5
- const paths_1 = require("./paths");
6
- const configWebpack = (config, { name, helpers }) => {
7
- if (name === shared_1.BUNDLER_TARGET_SERVER) {
8
- const tracePath = (0, paths_1.resolveLocal)('@shuvi/service', 'lib/trace');
9
- helpers.addExternals(config, ({ request }, next) => {
10
- switch (request) {
11
- // trace is a singleton, so we don't want to bundle it
12
- case '@shuvi/service/lib/trace': {
13
- next(null, `commonjs ${tracePath}`);
14
- break;
15
- }
16
- default: {
17
- next(null, 'next');
18
- }
19
- }
20
- });
21
- }
22
- return config;
23
- };
24
- exports.default = {
25
- core: (0, service_1.createPlugin)({
26
- configWebpack
27
- })
28
- };