@tramvai/module-server 2.79.7 → 2.82.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/lib/modules/serverTiming.d.ts +1 -4
- package/lib/server/error.d.ts +4 -3
- package/lib/server/error.es.js +93 -16
- package/lib/server/error.js +93 -16
- package/lib/server/webApp.d.ts +4 -3
- package/lib/server/webApp.es.js +2 -2
- package/lib/server/webApp.js +2 -2
- package/lib/server.es.js +3 -2
- package/lib/server.js +2 -1
- package/package.json +17 -14
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
export declare const ServerTimingModule: import("@tinkoff/dippy/lib/modules/module.h").ModuleClass & Partial<import("@tinkoff/dippy/lib/modules/module.h").ModuleSecretParameters> & {
|
|
2
|
-
[x: string]: (...args: any[]) =>
|
|
3
|
-
mainModule: import("@tramvai/core").ModuleType<import("@tinkoff/dippy/lib/modules/module.h").ModuleClass>;
|
|
4
|
-
providers: import("@tramvai/core").Provider<any, any>[];
|
|
5
|
-
};
|
|
2
|
+
[x: string]: (...args: any[]) => import("@tramvai/core").ModuleType<import("@tinkoff/dippy/lib/modules/module.h").ModuleClass>;
|
|
6
3
|
};
|
package/lib/server/error.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { FastifyInstance } from 'fastify';
|
|
2
2
|
import type { LOGGER_TOKEN } from '@tramvai/module-common';
|
|
3
|
-
import type { WEB_FASTIFY_APP_AFTER_ERROR_TOKEN, WEB_FASTIFY_APP_BEFORE_ERROR_TOKEN
|
|
3
|
+
import type { WEB_FASTIFY_APP_AFTER_ERROR_TOKEN, WEB_FASTIFY_APP_BEFORE_ERROR_TOKEN } from '@tramvai/tokens-server-private';
|
|
4
4
|
import type { ExtractDependencyType } from '@tinkoff/dippy';
|
|
5
|
-
|
|
5
|
+
import type { ROOT_ERROR_BOUNDARY_COMPONENT_TOKEN } from '@tramvai/react';
|
|
6
|
+
export declare const errorHandler: (app: FastifyInstance, { log, beforeError, afterError, RootErrorBoundary, }: {
|
|
6
7
|
log: ReturnType<typeof LOGGER_TOKEN>;
|
|
7
8
|
beforeError: ExtractDependencyType<typeof WEB_FASTIFY_APP_BEFORE_ERROR_TOKEN>;
|
|
8
|
-
processError: ExtractDependencyType<typeof WEB_FASTIFY_APP_PROCESS_ERROR_TOKEN>;
|
|
9
9
|
afterError: ExtractDependencyType<typeof WEB_FASTIFY_APP_AFTER_ERROR_TOKEN>;
|
|
10
|
+
RootErrorBoundary?: ExtractDependencyType<typeof ROOT_ERROR_BOUNDARY_COMPONENT_TOKEN>;
|
|
10
11
|
}) => void;
|
package/lib/server/error.es.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import isNil from '@tinkoff/utils/is/nil';
|
|
2
|
+
import { createElement } from 'react';
|
|
3
|
+
import { renderToString } from 'react-dom/server';
|
|
4
|
+
import { parse } from '@tinkoff/url';
|
|
2
5
|
import { isRedirectFoundError, isNotFoundError, isHttpError } from '@tinkoff/errors';
|
|
3
6
|
|
|
4
|
-
const errorHandler = (app, { log, beforeError,
|
|
7
|
+
const errorHandler = (app, { log, beforeError, afterError, RootErrorBoundary, }) => {
|
|
8
|
+
// eslint-disable-next-line max-statements
|
|
5
9
|
app.setErrorHandler(async (error, request, reply) => {
|
|
6
10
|
const runHandlers = async (handlers) => {
|
|
7
11
|
if (handlers) {
|
|
@@ -13,40 +17,113 @@ const errorHandler = (app, { log, beforeError, processError, afterError, }) => {
|
|
|
13
17
|
}
|
|
14
18
|
}
|
|
15
19
|
};
|
|
20
|
+
const beforeErrorResult = await runHandlers(beforeError);
|
|
21
|
+
if (!isNil(beforeErrorResult)) {
|
|
22
|
+
return beforeErrorResult;
|
|
23
|
+
}
|
|
16
24
|
const requestInfo = {
|
|
17
25
|
ip: request.ip,
|
|
18
26
|
requestId: request.headers['x-request-id'],
|
|
19
27
|
url: request.url,
|
|
20
28
|
};
|
|
21
|
-
const beforeErrorResult = await runHandlers(beforeError);
|
|
22
|
-
if (!isNil(beforeErrorResult)) {
|
|
23
|
-
return beforeErrorResult;
|
|
24
|
-
}
|
|
25
29
|
if (isRedirectFoundError(error)) {
|
|
30
|
+
log.info({
|
|
31
|
+
event: 'redirect-found-error',
|
|
32
|
+
message: `RedirectFoundError, redirect to ${error.nextUrl}, action execution will be aborted.
|
|
33
|
+
More information about redirects - https://tramvai.dev/docs/features/routing/redirects`,
|
|
34
|
+
error,
|
|
35
|
+
requestInfo,
|
|
36
|
+
});
|
|
26
37
|
reply.header('cache-control', 'no-cache, no-store, must-revalidate');
|
|
27
38
|
reply.redirect(error.httpStatus || 307, error.nextUrl);
|
|
28
39
|
return;
|
|
29
40
|
}
|
|
41
|
+
let httpStatus;
|
|
42
|
+
let logLevel;
|
|
43
|
+
let logEvent;
|
|
44
|
+
let logMessage;
|
|
30
45
|
if (isNotFoundError(error)) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return processErrorResult;
|
|
46
|
+
httpStatus = error.httpStatus || 404;
|
|
47
|
+
logLevel = 'info';
|
|
48
|
+
logEvent = 'not-found-error';
|
|
49
|
+
logMessage = `NotFoundError, action execution will be aborted.
|
|
50
|
+
Not Found page is common use-case with this error - https://tramvai.dev/docs/features/routing/wildcard-routes/#not-found-page`;
|
|
37
51
|
}
|
|
38
|
-
if (isHttpError(error)) {
|
|
52
|
+
else if (isHttpError(error)) {
|
|
53
|
+
httpStatus = error.httpStatus || 500;
|
|
39
54
|
if (error.httpStatus >= 500) {
|
|
40
|
-
|
|
55
|
+
logLevel = 'error';
|
|
56
|
+
logEvent = 'send-server-error';
|
|
57
|
+
logMessage = `This is expected server error, here is most common cases:
|
|
58
|
+
- Router Guard blocked request - https://tramvai.dev/docs/features/routing/hooks-and-guards#guards
|
|
59
|
+
- Forced Page Error Boundary render with 5xx code in Guard or Action - https://tramvai.dev/docs/features/error-boundaries#force-render-page-error-boundary-in-action`;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
logLevel = 'info';
|
|
63
|
+
logEvent = 'http-error';
|
|
64
|
+
logMessage = `This is expected server error, here is most common cases:
|
|
65
|
+
- Route is not found - https://tramvai.dev/docs/features/routing/flow#server-navigation
|
|
66
|
+
- Forced Page Error Boundary render with 4xx code in Guard or Action - https://tramvai.dev/docs/features/error-boundaries#force-render-page-error-boundary-in-action
|
|
67
|
+
- Request Limiter blocked request with 429 code - https://tramvai.dev/docs/references/modules/request-limiter/`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
httpStatus = error.statusCode || 500;
|
|
72
|
+
if (error.statusCode >= 500) {
|
|
73
|
+
logLevel = 'error';
|
|
74
|
+
logEvent = 'send-server-error';
|
|
75
|
+
logMessage = `This is Fastify 5xx error, you can check ${error.code} code in https://www.fastify.io/docs/latest/Reference/Errors/#${error.code.toLowerCase()} page`;
|
|
76
|
+
}
|
|
77
|
+
else if (error.statusCode >= 400) {
|
|
78
|
+
// a lot of noise with FST_ERR_CTP_INVALID_MEDIA_TYPE 4xx logs from Fastify,
|
|
79
|
+
// when somebody tries to scan our site and send some unsupported content types
|
|
80
|
+
logLevel = 'info';
|
|
81
|
+
logEvent = 'fastify-error-4xx';
|
|
82
|
+
logMessage = `This is Fastify 4xx error, you can check ${error.code} code in https://www.fastify.io/docs/latest/Reference/Errors/#${error.code.toLowerCase()} page`;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
logLevel = 'error';
|
|
86
|
+
logEvent = 'send-server-error';
|
|
87
|
+
logMessage = `Unexpected server error. Error cause will be in "error" parameter.
|
|
88
|
+
Most likely an error has occurred in the rendering of the current React page component
|
|
89
|
+
You can try to find relative logs by using "x-request-id" header`;
|
|
41
90
|
}
|
|
42
|
-
reply.status(error.httpStatus);
|
|
43
|
-
return '';
|
|
44
91
|
}
|
|
45
|
-
|
|
92
|
+
logMessage = `${logMessage}
|
|
93
|
+
${RootErrorBoundary
|
|
94
|
+
? 'Root Error Boundary will be rendered for the client'
|
|
95
|
+
: 'You can add Error Boundary for better UX - https://tramvai.dev/docs/features/error-boundaries'}'`;
|
|
96
|
+
log[logLevel]({
|
|
97
|
+
event: logEvent,
|
|
98
|
+
message: logMessage,
|
|
99
|
+
error,
|
|
100
|
+
requestInfo,
|
|
101
|
+
});
|
|
46
102
|
const afterErrorResult = await runHandlers(afterError);
|
|
47
103
|
if (!isNil(afterErrorResult)) {
|
|
48
104
|
return afterErrorResult;
|
|
49
105
|
}
|
|
106
|
+
reply.status(httpStatus);
|
|
107
|
+
if (RootErrorBoundary) {
|
|
108
|
+
try {
|
|
109
|
+
const body = renderToString(createElement(RootErrorBoundary, { error, url: parse(request.url) }));
|
|
110
|
+
log.info({
|
|
111
|
+
event: 'render-root-error-boundary',
|
|
112
|
+
message: 'Render Root Error Boundary for the client',
|
|
113
|
+
});
|
|
114
|
+
reply.header('Content-Type', 'text/html; charset=utf-8');
|
|
115
|
+
reply.header('Content-Length', Buffer.byteLength(body, 'utf8'));
|
|
116
|
+
reply.header('Cache-Control', 'no-cache, no-store, must-revalidate');
|
|
117
|
+
return body;
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
log.warn({
|
|
121
|
+
event: 'failed-root-error-boundary',
|
|
122
|
+
message: 'Root Error Boundary rendering failed',
|
|
123
|
+
error: e,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
50
127
|
throw error;
|
|
51
128
|
});
|
|
52
129
|
};
|
package/lib/server/error.js
CHANGED
|
@@ -3,13 +3,17 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var isNil = require('@tinkoff/utils/is/nil');
|
|
6
|
+
var react = require('react');
|
|
7
|
+
var server = require('react-dom/server');
|
|
8
|
+
var url = require('@tinkoff/url');
|
|
6
9
|
var errors = require('@tinkoff/errors');
|
|
7
10
|
|
|
8
11
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
12
|
|
|
10
13
|
var isNil__default = /*#__PURE__*/_interopDefaultLegacy(isNil);
|
|
11
14
|
|
|
12
|
-
const errorHandler = (app, { log, beforeError,
|
|
15
|
+
const errorHandler = (app, { log, beforeError, afterError, RootErrorBoundary, }) => {
|
|
16
|
+
// eslint-disable-next-line max-statements
|
|
13
17
|
app.setErrorHandler(async (error, request, reply) => {
|
|
14
18
|
const runHandlers = async (handlers) => {
|
|
15
19
|
if (handlers) {
|
|
@@ -21,40 +25,113 @@ const errorHandler = (app, { log, beforeError, processError, afterError, }) => {
|
|
|
21
25
|
}
|
|
22
26
|
}
|
|
23
27
|
};
|
|
28
|
+
const beforeErrorResult = await runHandlers(beforeError);
|
|
29
|
+
if (!isNil__default["default"](beforeErrorResult)) {
|
|
30
|
+
return beforeErrorResult;
|
|
31
|
+
}
|
|
24
32
|
const requestInfo = {
|
|
25
33
|
ip: request.ip,
|
|
26
34
|
requestId: request.headers['x-request-id'],
|
|
27
35
|
url: request.url,
|
|
28
36
|
};
|
|
29
|
-
const beforeErrorResult = await runHandlers(beforeError);
|
|
30
|
-
if (!isNil__default["default"](beforeErrorResult)) {
|
|
31
|
-
return beforeErrorResult;
|
|
32
|
-
}
|
|
33
37
|
if (errors.isRedirectFoundError(error)) {
|
|
38
|
+
log.info({
|
|
39
|
+
event: 'redirect-found-error',
|
|
40
|
+
message: `RedirectFoundError, redirect to ${error.nextUrl}, action execution will be aborted.
|
|
41
|
+
More information about redirects - https://tramvai.dev/docs/features/routing/redirects`,
|
|
42
|
+
error,
|
|
43
|
+
requestInfo,
|
|
44
|
+
});
|
|
34
45
|
reply.header('cache-control', 'no-cache, no-store, must-revalidate');
|
|
35
46
|
reply.redirect(error.httpStatus || 307, error.nextUrl);
|
|
36
47
|
return;
|
|
37
48
|
}
|
|
49
|
+
let httpStatus;
|
|
50
|
+
let logLevel;
|
|
51
|
+
let logEvent;
|
|
52
|
+
let logMessage;
|
|
38
53
|
if (errors.isNotFoundError(error)) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return processErrorResult;
|
|
54
|
+
httpStatus = error.httpStatus || 404;
|
|
55
|
+
logLevel = 'info';
|
|
56
|
+
logEvent = 'not-found-error';
|
|
57
|
+
logMessage = `NotFoundError, action execution will be aborted.
|
|
58
|
+
Not Found page is common use-case with this error - https://tramvai.dev/docs/features/routing/wildcard-routes/#not-found-page`;
|
|
45
59
|
}
|
|
46
|
-
if (errors.isHttpError(error)) {
|
|
60
|
+
else if (errors.isHttpError(error)) {
|
|
61
|
+
httpStatus = error.httpStatus || 500;
|
|
47
62
|
if (error.httpStatus >= 500) {
|
|
48
|
-
|
|
63
|
+
logLevel = 'error';
|
|
64
|
+
logEvent = 'send-server-error';
|
|
65
|
+
logMessage = `This is expected server error, here is most common cases:
|
|
66
|
+
- Router Guard blocked request - https://tramvai.dev/docs/features/routing/hooks-and-guards#guards
|
|
67
|
+
- Forced Page Error Boundary render with 5xx code in Guard or Action - https://tramvai.dev/docs/features/error-boundaries#force-render-page-error-boundary-in-action`;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
logLevel = 'info';
|
|
71
|
+
logEvent = 'http-error';
|
|
72
|
+
logMessage = `This is expected server error, here is most common cases:
|
|
73
|
+
- Route is not found - https://tramvai.dev/docs/features/routing/flow#server-navigation
|
|
74
|
+
- Forced Page Error Boundary render with 4xx code in Guard or Action - https://tramvai.dev/docs/features/error-boundaries#force-render-page-error-boundary-in-action
|
|
75
|
+
- Request Limiter blocked request with 429 code - https://tramvai.dev/docs/references/modules/request-limiter/`;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
httpStatus = error.statusCode || 500;
|
|
80
|
+
if (error.statusCode >= 500) {
|
|
81
|
+
logLevel = 'error';
|
|
82
|
+
logEvent = 'send-server-error';
|
|
83
|
+
logMessage = `This is Fastify 5xx error, you can check ${error.code} code in https://www.fastify.io/docs/latest/Reference/Errors/#${error.code.toLowerCase()} page`;
|
|
84
|
+
}
|
|
85
|
+
else if (error.statusCode >= 400) {
|
|
86
|
+
// a lot of noise with FST_ERR_CTP_INVALID_MEDIA_TYPE 4xx logs from Fastify,
|
|
87
|
+
// when somebody tries to scan our site and send some unsupported content types
|
|
88
|
+
logLevel = 'info';
|
|
89
|
+
logEvent = 'fastify-error-4xx';
|
|
90
|
+
logMessage = `This is Fastify 4xx error, you can check ${error.code} code in https://www.fastify.io/docs/latest/Reference/Errors/#${error.code.toLowerCase()} page`;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
logLevel = 'error';
|
|
94
|
+
logEvent = 'send-server-error';
|
|
95
|
+
logMessage = `Unexpected server error. Error cause will be in "error" parameter.
|
|
96
|
+
Most likely an error has occurred in the rendering of the current React page component
|
|
97
|
+
You can try to find relative logs by using "x-request-id" header`;
|
|
49
98
|
}
|
|
50
|
-
reply.status(error.httpStatus);
|
|
51
|
-
return '';
|
|
52
99
|
}
|
|
53
|
-
|
|
100
|
+
logMessage = `${logMessage}
|
|
101
|
+
${RootErrorBoundary
|
|
102
|
+
? 'Root Error Boundary will be rendered for the client'
|
|
103
|
+
: 'You can add Error Boundary for better UX - https://tramvai.dev/docs/features/error-boundaries'}'`;
|
|
104
|
+
log[logLevel]({
|
|
105
|
+
event: logEvent,
|
|
106
|
+
message: logMessage,
|
|
107
|
+
error,
|
|
108
|
+
requestInfo,
|
|
109
|
+
});
|
|
54
110
|
const afterErrorResult = await runHandlers(afterError);
|
|
55
111
|
if (!isNil__default["default"](afterErrorResult)) {
|
|
56
112
|
return afterErrorResult;
|
|
57
113
|
}
|
|
114
|
+
reply.status(httpStatus);
|
|
115
|
+
if (RootErrorBoundary) {
|
|
116
|
+
try {
|
|
117
|
+
const body = server.renderToString(react.createElement(RootErrorBoundary, { error, url: url.parse(request.url) }));
|
|
118
|
+
log.info({
|
|
119
|
+
event: 'render-root-error-boundary',
|
|
120
|
+
message: 'Render Root Error Boundary for the client',
|
|
121
|
+
});
|
|
122
|
+
reply.header('Content-Type', 'text/html; charset=utf-8');
|
|
123
|
+
reply.header('Content-Length', Buffer.byteLength(body, 'utf8'));
|
|
124
|
+
reply.header('Cache-Control', 'no-cache, no-store, must-revalidate');
|
|
125
|
+
return body;
|
|
126
|
+
}
|
|
127
|
+
catch (e) {
|
|
128
|
+
log.warn({
|
|
129
|
+
event: 'failed-root-error-boundary',
|
|
130
|
+
message: 'Root Error Boundary rendering failed',
|
|
131
|
+
error: e,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
58
135
|
throw error;
|
|
59
136
|
});
|
|
60
137
|
};
|
package/lib/server/webApp.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { EXECUTION_CONTEXT_MANAGER_TOKEN, LOGGER_TOKEN } from '@tramvai/tokens-common';
|
|
2
2
|
import type { COMMAND_LINE_RUNNER_TOKEN } from '@tramvai/core';
|
|
3
3
|
import type { SERVER_TOKEN } from '@tramvai/tokens-server';
|
|
4
|
-
import type { WEB_FASTIFY_APP_TOKEN, WEB_FASTIFY_APP_AFTER_INIT_TOKEN, WEB_FASTIFY_APP_BEFORE_INIT_TOKEN, WEB_FASTIFY_APP_INIT_TOKEN, WEB_FASTIFY_APP_LIMITER_TOKEN, WEB_FASTIFY_APP_BEFORE_ERROR_TOKEN, WEB_FASTIFY_APP_AFTER_ERROR_TOKEN,
|
|
4
|
+
import type { WEB_FASTIFY_APP_TOKEN, WEB_FASTIFY_APP_AFTER_INIT_TOKEN, WEB_FASTIFY_APP_BEFORE_INIT_TOKEN, WEB_FASTIFY_APP_INIT_TOKEN, WEB_FASTIFY_APP_LIMITER_TOKEN, WEB_FASTIFY_APP_BEFORE_ERROR_TOKEN, WEB_FASTIFY_APP_AFTER_ERROR_TOKEN, WEB_FASTIFY_APP_METRICS_TOKEN } from '@tramvai/tokens-server-private';
|
|
5
5
|
import type { ExtractDependencyType } from '@tinkoff/dippy';
|
|
6
|
+
import type { ROOT_ERROR_BOUNDARY_COMPONENT_TOKEN } from '@tramvai/react';
|
|
6
7
|
export declare const webAppFactory: ({ server }: {
|
|
7
8
|
server: typeof SERVER_TOKEN;
|
|
8
9
|
}) => import("fastify").FastifyInstance<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault> & PromiseLike<import("fastify").FastifyInstance<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>>;
|
|
9
|
-
export declare const webAppInitCommand: ({ app, logger, commandLineRunner, executionContextManager, beforeInit, requestMetrics, limiterRequest, init, afterInit, beforeError,
|
|
10
|
+
export declare const webAppInitCommand: ({ app, logger, commandLineRunner, executionContextManager, beforeInit, requestMetrics, limiterRequest, init, afterInit, beforeError, afterError, RootErrorBoundary, }: {
|
|
10
11
|
app: ExtractDependencyType<typeof WEB_FASTIFY_APP_TOKEN>;
|
|
11
12
|
logger: ExtractDependencyType<typeof LOGGER_TOKEN>;
|
|
12
13
|
commandLineRunner: ExtractDependencyType<typeof COMMAND_LINE_RUNNER_TOKEN>;
|
|
@@ -17,6 +18,6 @@ export declare const webAppInitCommand: ({ app, logger, commandLineRunner, execu
|
|
|
17
18
|
init: ExtractDependencyType<typeof WEB_FASTIFY_APP_INIT_TOKEN>;
|
|
18
19
|
afterInit: ExtractDependencyType<typeof WEB_FASTIFY_APP_AFTER_INIT_TOKEN>;
|
|
19
20
|
beforeError: ExtractDependencyType<typeof WEB_FASTIFY_APP_BEFORE_ERROR_TOKEN>;
|
|
20
|
-
processError: ExtractDependencyType<typeof WEB_FASTIFY_APP_PROCESS_ERROR_TOKEN>;
|
|
21
21
|
afterError: ExtractDependencyType<typeof WEB_FASTIFY_APP_AFTER_ERROR_TOKEN>;
|
|
22
|
+
RootErrorBoundary?: ExtractDependencyType<typeof ROOT_ERROR_BOUNDARY_COMPONENT_TOKEN>;
|
|
22
23
|
}) => () => Promise<void>;
|
package/lib/server/webApp.es.js
CHANGED
|
@@ -18,13 +18,13 @@ const webAppFactory = ({ server }) => {
|
|
|
18
18
|
});
|
|
19
19
|
return app;
|
|
20
20
|
};
|
|
21
|
-
const webAppInitCommand = ({ app, logger, commandLineRunner, executionContextManager, beforeInit, requestMetrics, limiterRequest, init, afterInit, beforeError,
|
|
21
|
+
const webAppInitCommand = ({ app, logger, commandLineRunner, executionContextManager, beforeInit, requestMetrics, limiterRequest, init, afterInit, beforeError, afterError, RootErrorBoundary, }) => {
|
|
22
22
|
const log = logger('server:webapp');
|
|
23
23
|
const runHandlers = (instance, handlers) => {
|
|
24
24
|
return Promise.all([handlers && Promise.all(handlers.map((handler) => handler(instance)))]);
|
|
25
25
|
};
|
|
26
26
|
return async function webAppInit() {
|
|
27
|
-
errorHandler(app, { log, beforeError,
|
|
27
|
+
errorHandler(app, { log, beforeError, afterError, RootErrorBoundary });
|
|
28
28
|
await app.register(async (instance) => {
|
|
29
29
|
await runHandlers(instance, beforeInit);
|
|
30
30
|
});
|
package/lib/server/webApp.js
CHANGED
|
@@ -27,13 +27,13 @@ const webAppFactory = ({ server }) => {
|
|
|
27
27
|
});
|
|
28
28
|
return app;
|
|
29
29
|
};
|
|
30
|
-
const webAppInitCommand = ({ app, logger, commandLineRunner, executionContextManager, beforeInit, requestMetrics, limiterRequest, init, afterInit, beforeError,
|
|
30
|
+
const webAppInitCommand = ({ app, logger, commandLineRunner, executionContextManager, beforeInit, requestMetrics, limiterRequest, init, afterInit, beforeError, afterError, RootErrorBoundary, }) => {
|
|
31
31
|
const log = logger('server:webapp');
|
|
32
32
|
const runHandlers = (instance, handlers) => {
|
|
33
33
|
return Promise.all([handlers && Promise.all(handlers.map((handler) => handler(instance)))]);
|
|
34
34
|
};
|
|
35
35
|
return async function webAppInit() {
|
|
36
|
-
error.errorHandler(app, { log, beforeError,
|
|
36
|
+
error.errorHandler(app, { log, beforeError, afterError, RootErrorBoundary });
|
|
37
37
|
await app.register(async (instance) => {
|
|
38
38
|
await runHandlers(instance, beforeInit);
|
|
39
39
|
});
|
package/lib/server.es.js
CHANGED
|
@@ -4,10 +4,11 @@ import EventEmitter from 'events';
|
|
|
4
4
|
import { Module, provide, Scope, commandLineListTokens, COMMAND_LINE_RUNNER_TOKEN, APP_INFO_TOKEN } from '@tramvai/core';
|
|
5
5
|
import { SERVER_TOKEN } from '@tramvai/tokens-server';
|
|
6
6
|
export * from '@tramvai/tokens-server';
|
|
7
|
-
import { SERVER_FACTORY_TOKEN, WEB_FASTIFY_APP_FACTORY_TOKEN, WEB_FASTIFY_APP_TOKEN, WEB_FASTIFY_APP_BEFORE_INIT_TOKEN, WEB_FASTIFY_APP_INIT_TOKEN, WEB_FASTIFY_APP_AFTER_INIT_TOKEN, WEB_FASTIFY_APP_METRICS_TOKEN, WEB_FASTIFY_APP_LIMITER_TOKEN, WEB_FASTIFY_APP_BEFORE_ERROR_TOKEN,
|
|
7
|
+
import { SERVER_FACTORY_TOKEN, WEB_FASTIFY_APP_FACTORY_TOKEN, WEB_FASTIFY_APP_TOKEN, WEB_FASTIFY_APP_BEFORE_INIT_TOKEN, WEB_FASTIFY_APP_INIT_TOKEN, WEB_FASTIFY_APP_AFTER_INIT_TOKEN, WEB_FASTIFY_APP_METRICS_TOKEN, WEB_FASTIFY_APP_LIMITER_TOKEN, WEB_FASTIFY_APP_BEFORE_ERROR_TOKEN, WEB_FASTIFY_APP_AFTER_ERROR_TOKEN } from '@tramvai/tokens-server-private';
|
|
8
8
|
import { LOGGER_TOKEN, EXECUTION_CONTEXT_MANAGER_TOKEN, ENV_MANAGER_TOKEN, ENV_USED_TOKEN } from '@tramvai/tokens-common';
|
|
9
9
|
import { MetricsModule } from '@tramvai/module-metrics';
|
|
10
10
|
import { CacheWarmupModule } from '@tramvai/module-cache-warmup';
|
|
11
|
+
import { ROOT_ERROR_BOUNDARY_COMPONENT_TOKEN } from '@tramvai/react';
|
|
11
12
|
import { serverFactory, serverListenCommand } from './server/server.es.js';
|
|
12
13
|
import { webAppFactory, webAppInitCommand } from './server/webApp.es.js';
|
|
13
14
|
import { staticAppCommand } from './server/static.es.js';
|
|
@@ -91,8 +92,8 @@ ServerModule = __decorate([
|
|
|
91
92
|
requestMetrics: { token: WEB_FASTIFY_APP_METRICS_TOKEN, optional: true },
|
|
92
93
|
limiterRequest: { token: WEB_FASTIFY_APP_LIMITER_TOKEN, optional: true },
|
|
93
94
|
beforeError: { token: WEB_FASTIFY_APP_BEFORE_ERROR_TOKEN, optional: true },
|
|
94
|
-
processError: { token: WEB_FASTIFY_APP_PROCESS_ERROR_TOKEN, optional: true },
|
|
95
95
|
afterError: { token: WEB_FASTIFY_APP_AFTER_ERROR_TOKEN, optional: true },
|
|
96
|
+
RootErrorBoundary: { token: ROOT_ERROR_BOUNDARY_COMPONENT_TOKEN, optional: true },
|
|
96
97
|
},
|
|
97
98
|
},
|
|
98
99
|
{
|
package/lib/server.js
CHANGED
|
@@ -11,6 +11,7 @@ var tokensServerPrivate = require('@tramvai/tokens-server-private');
|
|
|
11
11
|
var tokensCommon = require('@tramvai/tokens-common');
|
|
12
12
|
var moduleMetrics = require('@tramvai/module-metrics');
|
|
13
13
|
var moduleCacheWarmup = require('@tramvai/module-cache-warmup');
|
|
14
|
+
var react = require('@tramvai/react');
|
|
14
15
|
var server = require('./server/server.js');
|
|
15
16
|
var webApp = require('./server/webApp.js');
|
|
16
17
|
var _static = require('./server/static.js');
|
|
@@ -98,8 +99,8 @@ exports.ServerModule = tslib.__decorate([
|
|
|
98
99
|
requestMetrics: { token: tokensServerPrivate.WEB_FASTIFY_APP_METRICS_TOKEN, optional: true },
|
|
99
100
|
limiterRequest: { token: tokensServerPrivate.WEB_FASTIFY_APP_LIMITER_TOKEN, optional: true },
|
|
100
101
|
beforeError: { token: tokensServerPrivate.WEB_FASTIFY_APP_BEFORE_ERROR_TOKEN, optional: true },
|
|
101
|
-
processError: { token: tokensServerPrivate.WEB_FASTIFY_APP_PROCESS_ERROR_TOKEN, optional: true },
|
|
102
102
|
afterError: { token: tokensServerPrivate.WEB_FASTIFY_APP_AFTER_ERROR_TOKEN, optional: true },
|
|
103
|
+
RootErrorBoundary: { token: react.ROOT_ERROR_BOUNDARY_COMPONENT_TOKEN, optional: true },
|
|
103
104
|
},
|
|
104
105
|
},
|
|
105
106
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/module-server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.82.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"browser": "lib/browser.js",
|
|
6
6
|
"main": "lib/server.js",
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
"@tinkoff/monkeypatch": "2.0.5",
|
|
26
26
|
"@tinkoff/terminus": "0.1.8",
|
|
27
27
|
"@tinkoff/url": "0.8.6",
|
|
28
|
-
"@tramvai/module-cache-warmup": "2.
|
|
29
|
-
"@tramvai/module-metrics": "2.
|
|
30
|
-
"@tramvai/papi": "2.
|
|
31
|
-
"@tramvai/tokens-server": "2.
|
|
32
|
-
"@tramvai/tokens-server-private": "2.
|
|
28
|
+
"@tramvai/module-cache-warmup": "2.82.0",
|
|
29
|
+
"@tramvai/module-metrics": "2.82.0",
|
|
30
|
+
"@tramvai/papi": "2.82.0",
|
|
31
|
+
"@tramvai/tokens-server": "2.82.0",
|
|
32
|
+
"@tramvai/tokens-server-private": "2.82.0",
|
|
33
33
|
"fastify": "^4.14.1",
|
|
34
34
|
"@fastify/cookie": "^8.3.0",
|
|
35
35
|
"@fastify/compress": "^6.2.0",
|
|
@@ -38,15 +38,18 @@
|
|
|
38
38
|
"http-proxy-middleware": "^2.0.2"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@tinkoff/dippy": "0.8.
|
|
41
|
+
"@tinkoff/dippy": "0.8.15",
|
|
42
42
|
"@tinkoff/utils": "^2.1.2",
|
|
43
|
-
"@tramvai/cli": "2.
|
|
44
|
-
"@tramvai/core": "2.
|
|
45
|
-
"@tramvai/
|
|
46
|
-
"@tramvai/module-
|
|
47
|
-
"@tramvai/
|
|
48
|
-
"@tramvai/tokens-
|
|
49
|
-
"@tramvai/tokens-
|
|
43
|
+
"@tramvai/cli": "2.82.0",
|
|
44
|
+
"@tramvai/core": "2.82.0",
|
|
45
|
+
"@tramvai/react": "2.82.0",
|
|
46
|
+
"@tramvai/module-common": "2.82.0",
|
|
47
|
+
"@tramvai/module-environment": "2.82.0",
|
|
48
|
+
"@tramvai/tokens-common": "2.82.0",
|
|
49
|
+
"@tramvai/tokens-core-private": "2.82.0",
|
|
50
|
+
"@tramvai/tokens-render": "2.82.0",
|
|
51
|
+
"react": ">=16.14.0",
|
|
52
|
+
"react-dom": ">=16.14.0",
|
|
50
53
|
"tslib": "^2.4.0"
|
|
51
54
|
},
|
|
52
55
|
"devDependencies": {
|