@tramvai/module-server 1.84.2 → 1.90.1

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/server.js CHANGED
@@ -5,14 +5,20 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var tslib = require('tslib');
6
6
  var core = require('@tramvai/core');
7
7
  var tokensServer = require('@tramvai/tokens-server');
8
- var moduleCommon = require('@tramvai/module-common');
8
+ var tokensServerPrivate = require('@tramvai/tokens-server-private');
9
+ var tokensCommon = require('@tramvai/tokens-common');
9
10
  var moduleMetrics = require('@tramvai/module-metrics');
10
11
  var moduleCacheWarmup = require('@tramvai/module-cache-warmup');
11
12
  var http = require('http');
13
+ var fastify = require('fastify');
12
14
  var express = require('express');
13
15
  var cookieParser = require('cookie-parser');
14
16
  var bodyParser = require('body-parser');
15
- var finalhandler = require('finalhandler');
17
+ var fastifyCookie = require('fastify-cookie');
18
+ var fastifyFormBody = require('fastify-formbody');
19
+ var fp = require('fastify-plugin');
20
+ var symbols = require('fastify/lib/symbols');
21
+ var isNil = require('@tinkoff/utils/is/nil');
16
22
  var errors = require('@tinkoff/errors');
17
23
  var zlib = require('zlib');
18
24
  var compression = require('compression');
@@ -20,27 +26,31 @@ var os = require('os');
20
26
  var filterObj = require('@tinkoff/utils/object/filter');
21
27
  var flatten = require('@tinkoff/utils/array/flatten');
22
28
  var toArray = require('@tinkoff/utils/array/toArray');
23
- var tokensCommon = require('@tramvai/tokens-common');
24
29
  var papi = require('@tramvai/papi');
25
30
  var dippy = require('@tinkoff/dippy');
26
31
  var eachObj = require('@tinkoff/utils/object/each');
27
- var expressTerminus = require('@tinkoff/express-terminus');
32
+ var path = require('path');
33
+ var FastifyStatic = require('fastify-static');
34
+ var terminus = require('@tinkoff/terminus');
28
35
  var url = require('@tinkoff/url');
29
36
  var events = require('events');
30
37
  var monkeypatch = require('@tinkoff/monkeypatch');
31
38
  var https = require('https');
32
39
  var isArray = require('@tinkoff/utils/is/array');
33
40
  var isObject = require('@tinkoff/utils/is/object');
34
- var path = require('path');
35
41
  var httpProxyMiddleware = require('http-proxy-middleware');
36
42
 
37
43
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
38
44
 
39
45
  var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
46
+ var fastify__default = /*#__PURE__*/_interopDefaultLegacy(fastify);
40
47
  var express__default = /*#__PURE__*/_interopDefaultLegacy(express);
41
48
  var cookieParser__default = /*#__PURE__*/_interopDefaultLegacy(cookieParser);
42
49
  var bodyParser__default = /*#__PURE__*/_interopDefaultLegacy(bodyParser);
43
- var finalhandler__default = /*#__PURE__*/_interopDefaultLegacy(finalhandler);
50
+ var fastifyFormBody__default = /*#__PURE__*/_interopDefaultLegacy(fastifyFormBody);
51
+ var fp__default = /*#__PURE__*/_interopDefaultLegacy(fp);
52
+ var symbols__default = /*#__PURE__*/_interopDefaultLegacy(symbols);
53
+ var isNil__default = /*#__PURE__*/_interopDefaultLegacy(isNil);
44
54
  var zlib__default = /*#__PURE__*/_interopDefaultLegacy(zlib);
45
55
  var compression__default = /*#__PURE__*/_interopDefaultLegacy(compression);
46
56
  var os__default = /*#__PURE__*/_interopDefaultLegacy(os);
@@ -48,15 +58,14 @@ var filterObj__default = /*#__PURE__*/_interopDefaultLegacy(filterObj);
48
58
  var flatten__default = /*#__PURE__*/_interopDefaultLegacy(flatten);
49
59
  var toArray__default = /*#__PURE__*/_interopDefaultLegacy(toArray);
50
60
  var eachObj__default = /*#__PURE__*/_interopDefaultLegacy(eachObj);
61
+ var FastifyStatic__default = /*#__PURE__*/_interopDefaultLegacy(FastifyStatic);
51
62
  var monkeypatch__default = /*#__PURE__*/_interopDefaultLegacy(monkeypatch);
52
63
  var https__default = /*#__PURE__*/_interopDefaultLegacy(https);
53
64
  var isArray__default = /*#__PURE__*/_interopDefaultLegacy(isArray);
54
65
  var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
55
66
 
56
- const serverFactory = ({ webApp }) => {
57
- const server = http__default["default"].createServer();
58
- server.on('request', webApp);
59
- return server;
67
+ const serverFactory = () => {
68
+ return http__default["default"].createServer();
60
69
  };
61
70
  const serverListenCommand = ({ server, logger, envManager, }) => {
62
71
  const log = logger('server');
@@ -69,105 +78,236 @@ const serverListenCommand = ({ server, logger, envManager, }) => {
69
78
  };
70
79
  };
71
80
 
72
- const routerErrorHandler = (app) => {
73
- app.use((err, req, res, next) => {
74
- if (errors.isRedirectFoundError(err)) {
75
- res.setHeader('cache-control', 'no-cache, no-store, must-revalidate');
76
- return res.redirect(err.httpStatus || 307, err.nextUrl);
81
+ /**
82
+ * Fork of https://github.com/fastify/fastify-express
83
+ */
84
+ const kMiddlewares = Symbol('fastify-express-middlewares');
85
+ const expressPlugin = (fastify, options, next) => {
86
+ var _a, _b;
87
+ fastify.decorate('use', use);
88
+ // eslint-disable-next-line no-param-reassign
89
+ fastify[kMiddlewares] = [];
90
+ fastify.decorate('express', (_b = (_a = options.express) === null || _a === void 0 ? void 0 : _a.instance) !== null && _b !== void 0 ? _b : express__default["default"]());
91
+ fastify.express.disable('x-powered-by');
92
+ fastify
93
+ .addHook('onRequest', enhanceRequest)
94
+ .addHook('onRequest', runConnect)
95
+ .addHook('onRegister', onRegister);
96
+ function use(path, fn) {
97
+ if (typeof path === 'string') {
98
+ const prefix = this[symbols__default["default"].kRoutePrefix];
99
+ // eslint-disable-next-line no-param-reassign
100
+ path = prefix + (path === '/' && prefix.length > 0 ? '' : path);
77
101
  }
78
- if (errors.isNotFoundError(err)) {
79
- return res.status(404).end();
102
+ this[kMiddlewares].push([path, fn]);
103
+ if (fn == null) {
104
+ this.express.use(path);
80
105
  }
81
- next(err);
82
- });
106
+ else {
107
+ this.express.use(path, fn);
108
+ }
109
+ return this;
110
+ }
111
+ function enhanceRequest(req, reply, next) {
112
+ req.raw.originalUrl = req.raw.url;
113
+ req.raw.id = req.id;
114
+ req.raw.hostname = req.hostname;
115
+ req.raw.ip = req.ip;
116
+ req.raw.ips = req.ips;
117
+ req.raw.log = req.log;
118
+ // eslint-disable-next-line no-param-reassign
119
+ reply.raw.log = req.log;
120
+ const originalProtocol = req.raw.protocol;
121
+ // Make it lazy as it does a bit of work
122
+ Object.defineProperty(req.raw, 'protocol', {
123
+ get() {
124
+ // added in Fastify@3.5, so handle it missing
125
+ return req.protocol || originalProtocol;
126
+ },
127
+ });
128
+ next();
129
+ }
130
+ function runConnect(req, reply, next) {
131
+ if (this[kMiddlewares].length > 0) {
132
+ for (const [headerName, headerValue] of Object.entries(reply.getHeaders())) {
133
+ reply.raw.setHeader(headerName, headerValue);
134
+ }
135
+ this.express(req.raw, reply.raw, next);
136
+ }
137
+ else {
138
+ next();
139
+ }
140
+ }
141
+ function onRegister(instance) {
142
+ const middlewares = instance[kMiddlewares].slice();
143
+ // eslint-disable-next-line no-param-reassign
144
+ instance[kMiddlewares] = [];
145
+ instance.decorate('express', express__default["default"]());
146
+ instance.express.disable('x-powered-by');
147
+ instance.decorate('use', use);
148
+ for (const middleware of middlewares) {
149
+ instance.use(...middleware);
150
+ }
151
+ }
152
+ next();
83
153
  };
84
- const errorHandler = (app, { log, }) => {
85
- app.use(async (err, req, res, next) => {
154
+ const fastifyExpressCompatibility = fp__default["default"](expressPlugin, {
155
+ fastify: '>=3.0.0',
156
+ name: 'fastify-express',
157
+ });
158
+
159
+ const errorHandler = (app, { log, beforeError, processError, afterError, }) => {
160
+ app.setErrorHandler(async (error, request, reply) => {
161
+ const runHandlers = async (handlers) => {
162
+ if (handlers) {
163
+ for (const handler of handlers) {
164
+ const result = await handler(error, request, reply);
165
+ if (result) {
166
+ return result;
167
+ }
168
+ }
169
+ }
170
+ };
86
171
  const requestInfo = {
87
- ip: req.ip,
88
- requestId: req.headers['x-request-id'],
89
- url: req.url,
172
+ ip: request.ip,
173
+ requestId: request.headers['x-request-id'],
174
+ url: request.url,
90
175
  };
91
- if (errors.isHttpError(err)) {
92
- if (err.httpStatus >= 500) {
93
- log.error({ event: 'send-server-error', error: err, requestInfo });
176
+ const beforeErrorResult = await runHandlers(beforeError);
177
+ if (!isNil__default["default"](beforeErrorResult)) {
178
+ return beforeErrorResult;
179
+ }
180
+ if (errors.isRedirectFoundError(error)) {
181
+ reply.header('cache-control', 'no-cache, no-store, must-revalidate');
182
+ reply.redirect(error.httpStatus || 307, error.nextUrl);
183
+ return;
184
+ }
185
+ if (errors.isNotFoundError(error)) {
186
+ reply.status(404);
187
+ return '';
188
+ }
189
+ const processErrorResult = await runHandlers(processError);
190
+ if (!isNil__default["default"](processErrorResult)) {
191
+ return processErrorResult;
192
+ }
193
+ if (errors.isHttpError(error)) {
194
+ if (error.httpStatus >= 500) {
195
+ log.error({ event: 'send-server-error', error, requestInfo });
94
196
  }
95
- return res.status(err.httpStatus).end();
197
+ reply.status(error.httpStatus);
198
+ return '';
96
199
  }
97
- log.error({ event: 'send-server-error', error: err, requestInfo });
98
- finalhandler__default["default"](req, res)(err);
200
+ log.error({ event: 'send-server-error', error, requestInfo });
201
+ const afterErrorResult = await runHandlers(afterError);
202
+ if (!isNil__default["default"](afterErrorResult)) {
203
+ return afterErrorResult;
204
+ }
205
+ throw error;
99
206
  });
100
207
  };
101
208
 
102
- const webAppFactory = () => {
209
+ const webAppFactory = ({ server, expressApp, }) => {
210
+ const app = fastify__default["default"]({
211
+ serverFactory: (handler) => {
212
+ server.on('request', handler);
213
+ return server;
214
+ },
215
+ });
216
+ return app;
217
+ };
218
+ const webAppExpressFactory = ({ webApp }) => {
103
219
  const app = express__default["default"]();
104
220
  app.disable('etag');
105
221
  app.disable('x-powered-by');
106
222
  return app;
107
223
  };
108
- const webAppInitCommand = ({ app, logger, commandLineRunner, beforeInit, init, afterInit, limiterRequest, }) => {
224
+ const webAppInitCommand = ({ app, expressApp, logger, commandLineRunner, beforeInit, init, afterInit, limiterRequest, expressBeforeInit, expressInit, expressAfterInit, expressLimiterRequest, beforeError, processError, afterError, }) => {
109
225
  const log = logger('server:webapp');
110
- const runHandlers = (handlers) => {
111
- if (handlers) {
112
- return Promise.all(handlers.map((handler) => handler(app)));
113
- }
226
+ const runHandlers = (handlers, expressHandlers) => {
227
+ return Promise.all([
228
+ handlers && Promise.all(handlers.map((handler) => handler(app))),
229
+ expressHandlers && Promise.all(expressHandlers.map((handler) => handler(expressApp))),
230
+ ]);
114
231
  };
115
232
  return async function webAppInit() {
116
- await runHandlers(beforeInit);
117
- await runHandlers(limiterRequest);
118
- app.use(bodyParser__default["default"].urlencoded({
233
+ errorHandler(app, { log, beforeError, processError, afterError });
234
+ await app.register(fastifyExpressCompatibility, {
235
+ express: {
236
+ instance: expressApp,
237
+ },
238
+ });
239
+ await runHandlers(beforeInit, expressBeforeInit);
240
+ await runHandlers(limiterRequest, expressLimiterRequest);
241
+ await app.register(fastifyCookie.fastifyCookie);
242
+ await app.register(fastifyFormBody__default["default"]);
243
+ expressApp.use(bodyParser__default["default"].urlencoded({
119
244
  limit: '2mb',
120
245
  extended: false,
121
246
  }), cookieParser__default["default"]());
122
- await runHandlers(init);
123
- app.use(async (req, res, next) => {
247
+ await runHandlers(init, expressInit);
248
+ // force express to execute to update server's request and response instances
249
+ app.use((req, res, next) => {
250
+ next();
251
+ });
252
+ app.all('*', async (request, reply) => {
124
253
  try {
125
254
  log.debug({
126
255
  event: 'start:request',
127
256
  message: 'Клиент зашел на страницу',
128
- url: req.url,
257
+ url: request.url,
129
258
  });
130
259
  const di = await commandLineRunner.run('server', 'customer', [
131
260
  {
132
- provide: moduleCommon.REQUEST,
261
+ provide: tokensCommon.REQUEST,
133
262
  scope: core.Scope.REQUEST,
134
- useValue: req,
263
+ useValue: request.raw,
135
264
  },
136
265
  {
137
- provide: moduleCommon.RESPONSE,
266
+ provide: tokensCommon.RESPONSE,
138
267
  scope: core.Scope.REQUEST,
139
- useValue: res,
268
+ useValue: reply.raw,
269
+ },
270
+ // TODO: перевести использование на новые
271
+ // TODO: добавить для papi
272
+ {
273
+ provide: tokensCommon.FASTIFY_REQUEST,
274
+ scope: core.Scope.REQUEST,
275
+ useValue: request,
276
+ },
277
+ {
278
+ provide: tokensCommon.FASTIFY_RESPONSE,
279
+ scope: core.Scope.REQUEST,
280
+ useValue: reply,
140
281
  },
141
282
  ]);
142
- const responseManager = di.get(moduleCommon.RESPONSE_MANAGER_TOKEN);
143
- if (res.writableEnded) {
283
+ const responseManager = di.get(tokensCommon.RESPONSE_MANAGER_TOKEN);
284
+ if (reply.sent) {
144
285
  log.debug({
145
286
  event: 'response-ended',
146
287
  message: 'Response was already ended.',
147
- url: req.url,
288
+ url: request.url,
148
289
  });
149
290
  }
150
291
  else {
151
- res
152
- .set('content-type', 'text/html')
153
- .set(responseManager.getHeaders())
292
+ reply
293
+ .header('content-type', 'text/html')
294
+ .headers(responseManager.getHeaders())
154
295
  .status(responseManager.getStatus())
155
296
  .send(responseManager.getBody());
156
297
  }
157
298
  }
158
299
  catch (err) {
159
300
  if (err.di) {
160
- const responseManager = err.di.get(moduleCommon.RESPONSE_MANAGER_TOKEN);
161
- if (responseManager && !res.writableEnded) {
162
- res.set(responseManager.getHeaders());
301
+ const responseManager = err.di.get(tokensCommon.RESPONSE_MANAGER_TOKEN);
302
+ if (responseManager && !reply.sent) {
303
+ reply.headers(responseManager.getHeaders());
163
304
  }
164
305
  }
165
- next(err);
306
+ throw err;
166
307
  }
167
308
  });
168
- routerErrorHandler(app);
169
- await runHandlers(afterInit);
170
- errorHandler(app, { log });
309
+ await runHandlers(afterInit, expressAfterInit);
310
+ await app.ready();
171
311
  };
172
312
  };
173
313
 
@@ -211,9 +351,8 @@ const xHeadersFactory = ({ app, envManager, appInfo, }) => {
211
351
  'x-deploy-repository': envManager.get('DEPLOY_REPOSITORY'),
212
352
  });
213
353
  return async () => {
214
- app.use((req, res, next) => {
215
- res.set(xHeaders);
216
- next();
354
+ app.addHook('preHandler', async (_, reply) => {
355
+ reply.headers(xHeaders);
217
356
  });
218
357
  };
219
358
  };
@@ -257,10 +396,20 @@ try {
257
396
  Api = require('@tramvai/cli/lib/external/api').default; // eslint-disable-line import/no-unresolved
258
397
  }
259
398
  catch (e) { }
260
- const getFileApi = () => {
399
+ const getFileApi = ({ logger }) => {
400
+ const log = logger('papi:fileApi');
261
401
  const result = [];
262
402
  eachObj__default["default"]((v, k) => {
263
403
  const handler = (v.handler || v.default);
404
+ if (!handler) {
405
+ log.error({
406
+ message: `Cannot resolve a papi handler.
407
+ Check that you are using file based papi right way by docs https://tramvai.dev/docs/how-to/how-create-papi#automatic-handler-creation
408
+ In case you have not added any file papi handler, consider renaming directory ./src/api (by default) to the other name to resolve conflicts with papi, or
409
+ change settings application.commands.build.options.serverApiDir in tramvai.json`,
410
+ });
411
+ throw new Error('Not a papi');
412
+ }
264
413
  const papiParameters = papi.getPapiParameters(handler);
265
414
  result.push(papi.createPapiMethod({
266
415
  ...v,
@@ -274,7 +423,10 @@ const getFileApi = () => {
274
423
  const fileApiProvider = {
275
424
  provide: tokensServer.SERVER_MODULE_PAPI_PUBLIC_ROUTE,
276
425
  multi: true,
277
- useValue: getFileApi(),
426
+ useFactory: getFileApi,
427
+ deps: {
428
+ logger: tokensCommon.LOGGER_TOKEN,
429
+ },
278
430
  };
279
431
 
280
432
  const sharedProviders = [
@@ -409,29 +561,32 @@ let ServerStaticsModule = class ServerStaticsModule {
409
561
  ServerStaticsModule = tslib.__decorate([
410
562
  core.Module({
411
563
  providers: [
412
- {
413
- provide: tokensServer.WEB_APP_BEFORE_INIT_TOKEN,
564
+ core.provide({
565
+ provide: tokensServerPrivate.WEB_FASTIFY_APP_BEFORE_INIT_TOKEN,
414
566
  useFactory: ({ app, options }) => {
415
- const path = (options === null || options === void 0 ? void 0 : options.path) || 'public';
567
+ const path$1 = (options === null || options === void 0 ? void 0 : options.path) || 'public';
416
568
  return () => {
417
- app.use(express__default["default"].static(path, {
569
+ app.register(FastifyStatic__default["default"], {
570
+ decorateReply: false,
571
+ prefix: `/${path$1}`,
572
+ root: path.resolve(process.cwd(), path$1),
418
573
  setHeaders: (res) => {
419
574
  const oneYearForward = new Date(Date.now() + ONE_YEAR * 1000);
420
- res.set('cache-control', `public, max-age=${ONE_YEAR}`);
421
- res.set('expires', oneYearForward.toUTCString());
575
+ res.setHeader('cache-control', `public, max-age=${ONE_YEAR}`);
576
+ res.setHeader('expires', oneYearForward.toUTCString());
422
577
  },
423
- }));
578
+ });
424
579
  };
425
580
  },
426
581
  deps: {
427
- app: tokensServer.WEB_APP_TOKEN,
582
+ app: tokensServerPrivate.WEB_FASTIFY_APP_TOKEN,
428
583
  options: {
429
584
  token: tokensServer.SERVER_MODULE_STATICS_OPTIONS,
430
585
  optional: true,
431
586
  },
432
587
  },
433
588
  multi: true,
434
- },
589
+ }),
435
590
  ],
436
591
  })
437
592
  ], ServerStaticsModule);
@@ -447,12 +602,12 @@ ServerGracefulShutdownModule = tslib.__decorate([
447
602
  core.Module({
448
603
  providers: [
449
604
  {
450
- provide: tokensServer.WEB_APP_BEFORE_INIT_TOKEN,
605
+ provide: tokensServerPrivate.WEB_FASTIFY_APP_BEFORE_INIT_TOKEN,
451
606
  multi: true,
452
- useFactory: ({ server, app, logger, commandLineRunner, livenessProbe, readinessProbe, }) => {
607
+ useFactory: ({ app, server, logger, commandLineRunner, livenessProbe, readinessProbe, }) => {
453
608
  const log = logger('server');
454
609
  return function serverListen() {
455
- expressTerminus.createTerminus(server, app, {
610
+ terminus.createTerminus(server, app, {
456
611
  signal: 'SIGTERM',
457
612
  timeout: GRACEFUL_SHUTDOWN_TIMEOUT,
458
613
  logger: (msg, error) => {
@@ -492,8 +647,8 @@ ServerGracefulShutdownModule = tslib.__decorate([
492
647
  };
493
648
  },
494
649
  deps: {
650
+ app: tokensServerPrivate.WEB_FASTIFY_APP_TOKEN,
495
651
  server: tokensServer.SERVER_TOKEN,
496
- app: tokensServer.WEB_APP_TOKEN,
497
652
  logger: tokensCommon.LOGGER_TOKEN,
498
653
  commandLineRunner: core.COMMAND_LINE_RUNNER_TOKEN,
499
654
  readinessProbe: { token: tokensServer.READINESS_PROBE_TOKEN, optional: true },
@@ -656,6 +811,8 @@ ServerProxyModule = tslib.__decorate([
656
811
  core.Module({
657
812
  providers: [
658
813
  {
814
+ // TODO: tramvai@2 migrate to `fastify` and `fastify-http-proxy`
815
+ // interfaces for the proxies are not compatible so some migration from the app is needed
659
816
  provide: tokensServer.WEB_APP_BEFORE_INIT_TOKEN,
660
817
  useFactory: ({ app, defaultProxies }) => {
661
818
  return () => {
@@ -759,31 +916,48 @@ exports.ServerModule = tslib.__decorate([
759
916
  process.env.NODE_ENV !== 'production' && DebugHttpRequestsModule,
760
917
  ].filter(Boolean),
761
918
  providers: [
762
- {
763
- provide: tokensServer.WEB_APP_TOKEN,
919
+ core.provide({
920
+ provide: tokensServer.SERVER_TOKEN,
764
921
  scope: core.Scope.SINGLETON,
922
+ useFactory: serverFactory,
923
+ }),
924
+ core.provide({
925
+ provide: tokensServerPrivate.WEB_FASTIFY_APP_TOKEN,
765
926
  useFactory: webAppFactory,
766
- },
927
+ scope: core.Scope.SINGLETON,
928
+ deps: {
929
+ server: tokensServer.SERVER_TOKEN,
930
+ },
931
+ }),
932
+ core.provide({
933
+ // BACKWARD: provide the express app as before
934
+ provide: tokensServer.WEB_APP_TOKEN,
935
+ scope: core.Scope.SINGLETON,
936
+ useFactory: webAppExpressFactory,
937
+ deps: {
938
+ webApp: tokensServerPrivate.WEB_FASTIFY_APP_TOKEN,
939
+ },
940
+ }),
767
941
  {
768
942
  provide: core.commandLineListTokens.init,
769
943
  multi: true,
770
944
  useFactory: webAppInitCommand,
771
945
  deps: {
772
- app: tokensServer.WEB_APP_TOKEN,
773
- logger: moduleCommon.LOGGER_TOKEN,
946
+ app: tokensServerPrivate.WEB_FASTIFY_APP_TOKEN,
947
+ expressApp: tokensServer.WEB_APP_TOKEN,
948
+ logger: tokensCommon.LOGGER_TOKEN,
774
949
  commandLineRunner: core.COMMAND_LINE_RUNNER_TOKEN,
775
- beforeInit: { token: tokensServer.WEB_APP_BEFORE_INIT_TOKEN, optional: true },
776
- init: { token: tokensServer.WEB_APP_INIT_TOKEN, optional: true },
777
- afterInit: { token: tokensServer.WEB_APP_AFTER_INIT_TOKEN, optional: true },
778
- limiterRequest: { token: tokensServer.WEB_APP_LIMITER_TOKEN, optional: true },
779
- },
780
- },
781
- {
782
- provide: tokensServer.SERVER_TOKEN,
783
- scope: core.Scope.SINGLETON,
784
- useFactory: serverFactory,
785
- deps: {
786
- webApp: tokensServer.WEB_APP_TOKEN,
950
+ beforeInit: { token: tokensServerPrivate.WEB_FASTIFY_APP_BEFORE_INIT_TOKEN, optional: true },
951
+ init: { token: tokensServerPrivate.WEB_FASTIFY_APP_INIT_TOKEN, optional: true },
952
+ afterInit: { token: tokensServerPrivate.WEB_FASTIFY_APP_AFTER_INIT_TOKEN, optional: true },
953
+ limiterRequest: { token: tokensServerPrivate.WEB_FASTIFY_APP_LIMITER_TOKEN, optional: true },
954
+ expressBeforeInit: { token: tokensServer.WEB_APP_BEFORE_INIT_TOKEN, optional: true },
955
+ expressInit: { token: tokensServer.WEB_APP_INIT_TOKEN, optional: true },
956
+ expressAfterInit: { token: tokensServer.WEB_APP_AFTER_INIT_TOKEN, optional: true },
957
+ expressLimiterRequest: { token: tokensServer.WEB_APP_LIMITER_TOKEN, optional: true },
958
+ beforeError: { token: tokensServerPrivate.WEB_FASTIFY_APP_BEFORE_ERROR_TOKEN, optional: true },
959
+ processError: { token: tokensServerPrivate.WEB_FASTIFY_APP_PROCESS_ERROR_TOKEN, optional: true },
960
+ afterError: { token: tokensServerPrivate.WEB_FASTIFY_APP_AFTER_ERROR_TOKEN, optional: true },
787
961
  },
788
962
  },
789
963
  {
@@ -792,8 +966,8 @@ exports.ServerModule = tslib.__decorate([
792
966
  useFactory: serverListenCommand,
793
967
  deps: {
794
968
  server: tokensServer.SERVER_TOKEN,
795
- logger: moduleCommon.LOGGER_TOKEN,
796
- envManager: moduleCommon.ENV_MANAGER_TOKEN,
969
+ logger: tokensCommon.LOGGER_TOKEN,
970
+ envManager: tokensCommon.ENV_MANAGER_TOKEN,
797
971
  },
798
972
  },
799
973
  {
@@ -801,13 +975,13 @@ exports.ServerModule = tslib.__decorate([
801
975
  multi: true,
802
976
  useFactory: staticAppCommand,
803
977
  deps: {
804
- logger: moduleCommon.LOGGER_TOKEN,
805
- envManager: moduleCommon.ENV_MANAGER_TOKEN,
978
+ logger: tokensCommon.LOGGER_TOKEN,
979
+ envManager: tokensCommon.ENV_MANAGER_TOKEN,
806
980
  appInfo: core.APP_INFO_TOKEN,
807
981
  },
808
982
  },
809
983
  {
810
- provide: moduleCommon.ENV_USED_TOKEN,
984
+ provide: tokensCommon.ENV_USED_TOKEN,
811
985
  multi: true,
812
986
  useValue: [
813
987
  { key: 'DEV_STATIC', optional: true, dehydrate: false },
@@ -827,12 +1001,12 @@ exports.ServerModule = tslib.__decorate([
827
1001
  ],
828
1002
  },
829
1003
  {
830
- provide: tokensServer.WEB_APP_BEFORE_INIT_TOKEN,
1004
+ provide: tokensServerPrivate.WEB_FASTIFY_APP_INIT_TOKEN,
831
1005
  multi: true,
832
1006
  useFactory: xHeadersFactory,
833
1007
  deps: {
834
- app: tokensServer.WEB_APP_TOKEN,
835
- envManager: moduleCommon.ENV_MANAGER_TOKEN,
1008
+ app: tokensServerPrivate.WEB_FASTIFY_APP_TOKEN,
1009
+ envManager: tokensCommon.ENV_MANAGER_TOKEN,
836
1010
  appInfo: core.APP_INFO_TOKEN,
837
1011
  },
838
1012
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-server",
3
- "version": "1.84.2",
3
+ "version": "1.90.1",
4
4
  "description": "",
5
5
  "browser": "lib/browser.js",
6
6
  "main": "lib/server.js",
@@ -20,34 +20,38 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@tinkoff/errors": "0.2.20",
23
- "@tinkoff/express-terminus": "0.1.13",
24
23
  "@tinkoff/monkeypatch": "1.3.3",
24
+ "@tinkoff/terminus": "0.0.1",
25
25
  "@tinkoff/url": "0.7.37",
26
- "@tramvai/module-cache-warmup": "1.84.2",
27
- "@tramvai/module-metrics": "1.84.2",
28
- "@tramvai/papi": "1.84.2",
29
- "@tramvai/tokens-server": "1.84.2",
26
+ "@tramvai/module-cache-warmup": "1.90.1",
27
+ "@tramvai/module-metrics": "1.90.1",
28
+ "@tramvai/papi": "1.90.1",
29
+ "@tramvai/tokens-server": "1.90.1",
30
+ "@tramvai/tokens-server-private": "1.90.1",
30
31
  "body-parser": "^1.19.0",
31
32
  "compression": "^1.7.4",
32
33
  "cookie-parser": "^1.4.3",
33
34
  "express": "^4.17.1",
34
- "finalhandler": "^1.1.2",
35
+ "fastify": "^3.27.4",
36
+ "fastify-cookie": "^5.6.0",
37
+ "fastify-formbody": "^5.2.0",
38
+ "fastify-plugin": "^3.0.1",
39
+ "fastify-static": "^4.6.1",
35
40
  "http-proxy-middleware": "^2.0.2"
36
41
  },
37
42
  "peerDependencies": {
38
- "@tinkoff/utils": "^2.1.2",
39
- "@tramvai/cli": "1.84.2",
40
- "@tramvai/core": "1.84.2",
41
- "@tramvai/module-common": "1.84.2",
42
- "@tramvai/module-environment": "1.84.2",
43
- "@tramvai/tokens-common": "1.84.2",
44
43
  "@tinkoff/dippy": "0.7.39",
44
+ "@tinkoff/utils": "^2.1.2",
45
+ "@tramvai/cli": "1.90.1",
46
+ "@tramvai/core": "1.90.1",
47
+ "@tramvai/module-common": "1.90.1",
48
+ "@tramvai/module-environment": "1.90.1",
49
+ "@tramvai/tokens-common": "1.90.1",
45
50
  "tslib": "^2.0.3"
46
51
  },
47
52
  "devDependencies": {
48
53
  "@types/compression": "^1.7.0",
49
54
  "@types/express": "^4.17.9",
50
- "@types/finalhandler": "^1.1.0",
51
55
  "@types/http-proxy-middleware": "^0.19.3"
52
56
  },
53
57
  "module": "lib/server.es.js",