@tramvai/module-server 2.3.0 → 2.6.2

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/README.md CHANGED
@@ -182,6 +182,10 @@ Module uses loggers with identifiers: `server`, `server:static`, `server:webapp`
182
182
 
183
183
  ## How to
184
184
 
185
+ ### Setting `keepAliveTimeout` for the server
186
+
187
+ The default value for server's `keepAliveTimeout` is 5000. However, in case you want to set it manually just pass the environment variable `NODE_KEEPALIVE_TIMEOUT=[your_value]`. For further reading go to [NodeJs server.keepAliveTimeout page](https://nodejs.org/api/http.html#serverkeepalivetimeout).
188
+
185
189
  ### Specify server port
186
190
 
187
191
  By default server starts at `3000` port. You have next options to override this value depending on your environment:
@@ -5,3 +5,4 @@ export * from './debugRequests';
5
5
  export * from './proxy';
6
6
  export * from './dependenciesVersion';
7
7
  export * from './utilityServer';
8
+ export * from './keepAlive';
@@ -0,0 +1,2 @@
1
+ export declare class KeepAliveModule {
2
+ }
package/lib/server.es.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { __decorate } from 'tslib';
2
+ import { setDefaultResultOrder } from 'dns';
2
3
  import { Scope, APP_INFO_TOKEN, Module, provide, DI_TOKEN, COMMAND_LINE_RUNNER_TOKEN, commandLineListTokens, createToken } from '@tramvai/core';
3
4
  import { SERVER_MODULE_PAPI_PUBLIC_ROUTE, SERVER_MODULE_PAPI_PUBLIC_URL, SERVER_MODULE_PAPI_PRIVATE_URL, WEB_APP_BEFORE_INIT_TOKEN, WEB_APP_TOKEN, SERVER_MODULE_PAPI_PRIVATE_ROUTE, SERVER_MODULE_STATICS_OPTIONS, SERVER_TOKEN, READINESS_PROBE_TOKEN, LIVENESS_PROBE_TOKEN, UTILITY_SERVER_PATHS, PROXY_CONFIG_TOKEN, DEPENDENCIES_VERSION_FILTER_TOKEN, UTILITY_SERVER_PORT_TOKEN, WEB_APP_INIT_TOKEN, WEB_APP_AFTER_INIT_TOKEN, WEB_APP_LIMITER_TOKEN } from '@tramvai/tokens-server';
4
5
  export * from '@tramvai/tokens-server';
@@ -34,6 +35,7 @@ import https from 'https';
34
35
  import isArray from '@tinkoff/utils/is/array';
35
36
  import isObject from '@tinkoff/utils/is/object';
36
37
  import { createProxyMiddleware } from 'http-proxy-middleware';
38
+ import { ENV_MANAGER_TOKEN as ENV_MANAGER_TOKEN$1 } from '@tramvai/module-common';
37
39
 
38
40
  const serverFactory = () => {
39
41
  return http.createServer();
@@ -977,6 +979,49 @@ UtilityServerModule = __decorate([
977
979
  })
978
980
  ], UtilityServerModule);
979
981
 
982
+ let KeepAliveModule = class KeepAliveModule {
983
+ };
984
+ KeepAliveModule = __decorate([
985
+ Module({
986
+ providers: [
987
+ provide({
988
+ provide: ENV_USED_TOKEN,
989
+ useValue: [
990
+ {
991
+ key: 'NODE_KEEPALIVE_TIMEOUT',
992
+ optional: true,
993
+ validator(keepAliveTimeout) {
994
+ const value = Number(keepAliveTimeout);
995
+ if (Number.isNaN(value)) {
996
+ return 'Env variable NODE_KEEPALIVE_TIMEOUT should be a number';
997
+ }
998
+ if (value < 0) {
999
+ return 'Env variable NODE_KEEPALIVE_TIMEOUT should be greater or equal than 0';
1000
+ }
1001
+ return true;
1002
+ },
1003
+ },
1004
+ ],
1005
+ }),
1006
+ provide({
1007
+ provide: commandLineListTokens.init,
1008
+ useFactory: ({ server, envManager, }) => () => {
1009
+ const externalKeepAliveTimeout = envManager.get('NODE_KEEPALIVE_TIMEOUT');
1010
+ if (externalKeepAliveTimeout !== 'undefined') {
1011
+ // eslint-disable-next-line no-param-reassign
1012
+ server.keepAliveTimeout = Number(externalKeepAliveTimeout);
1013
+ }
1014
+ },
1015
+ multi: true,
1016
+ deps: { server: SERVER_TOKEN, envManager: ENV_MANAGER_TOKEN$1 },
1017
+ }),
1018
+ ],
1019
+ })
1020
+ ], KeepAliveModule);
1021
+
1022
+ if (typeof setDefaultResultOrder === 'function') {
1023
+ setDefaultResultOrder('ipv4first');
1024
+ }
980
1025
  let ServerModule = class ServerModule {
981
1026
  };
982
1027
  ServerModule = __decorate([
@@ -990,6 +1035,7 @@ ServerModule = __decorate([
990
1035
  ServerProxyModule,
991
1036
  DependenciesVersionModule,
992
1037
  UtilityServerModule,
1038
+ KeepAliveModule,
993
1039
  process.env.NODE_ENV !== 'production' && DebugHttpRequestsModule,
994
1040
  ].filter(Boolean),
995
1041
  providers: [
package/lib/server.js CHANGED
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var tslib = require('tslib');
6
+ var dns = require('dns');
6
7
  var core = require('@tramvai/core');
7
8
  var tokensServer = require('@tramvai/tokens-server');
8
9
  var tokensServerPrivate = require('@tramvai/tokens-server-private');
@@ -37,6 +38,7 @@ var https = require('https');
37
38
  var isArray = require('@tinkoff/utils/is/array');
38
39
  var isObject = require('@tinkoff/utils/is/object');
39
40
  var httpProxyMiddleware = require('http-proxy-middleware');
41
+ var moduleCommon = require('@tramvai/module-common');
40
42
 
41
43
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
42
44
 
@@ -1002,6 +1004,49 @@ UtilityServerModule = tslib.__decorate([
1002
1004
  })
1003
1005
  ], UtilityServerModule);
1004
1006
 
1007
+ let KeepAliveModule = class KeepAliveModule {
1008
+ };
1009
+ KeepAliveModule = tslib.__decorate([
1010
+ core.Module({
1011
+ providers: [
1012
+ core.provide({
1013
+ provide: tokensCommon.ENV_USED_TOKEN,
1014
+ useValue: [
1015
+ {
1016
+ key: 'NODE_KEEPALIVE_TIMEOUT',
1017
+ optional: true,
1018
+ validator(keepAliveTimeout) {
1019
+ const value = Number(keepAliveTimeout);
1020
+ if (Number.isNaN(value)) {
1021
+ return 'Env variable NODE_KEEPALIVE_TIMEOUT should be a number';
1022
+ }
1023
+ if (value < 0) {
1024
+ return 'Env variable NODE_KEEPALIVE_TIMEOUT should be greater or equal than 0';
1025
+ }
1026
+ return true;
1027
+ },
1028
+ },
1029
+ ],
1030
+ }),
1031
+ core.provide({
1032
+ provide: core.commandLineListTokens.init,
1033
+ useFactory: ({ server, envManager, }) => () => {
1034
+ const externalKeepAliveTimeout = envManager.get('NODE_KEEPALIVE_TIMEOUT');
1035
+ if (externalKeepAliveTimeout !== 'undefined') {
1036
+ // eslint-disable-next-line no-param-reassign
1037
+ server.keepAliveTimeout = Number(externalKeepAliveTimeout);
1038
+ }
1039
+ },
1040
+ multi: true,
1041
+ deps: { server: tokensServer.SERVER_TOKEN, envManager: moduleCommon.ENV_MANAGER_TOKEN },
1042
+ }),
1043
+ ],
1044
+ })
1045
+ ], KeepAliveModule);
1046
+
1047
+ if (typeof dns.setDefaultResultOrder === 'function') {
1048
+ dns.setDefaultResultOrder('ipv4first');
1049
+ }
1005
1050
  exports.ServerModule = class ServerModule {
1006
1051
  };
1007
1052
  exports.ServerModule = tslib.__decorate([
@@ -1015,6 +1060,7 @@ exports.ServerModule = tslib.__decorate([
1015
1060
  ServerProxyModule,
1016
1061
  DependenciesVersionModule,
1017
1062
  UtilityServerModule,
1063
+ KeepAliveModule,
1018
1064
  process.env.NODE_ENV !== 'production' && DebugHttpRequestsModule,
1019
1065
  ].filter(Boolean),
1020
1066
  providers: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-server",
3
- "version": "2.3.0",
3
+ "version": "2.6.2",
4
4
  "description": "",
5
5
  "browser": "lib/browser.js",
6
6
  "main": "lib/server.js",
@@ -8,7 +8,10 @@
8
8
  "files": [
9
9
  "lib"
10
10
  ],
11
- "sideEffects": false,
11
+ "sideEffects": [
12
+ "lib/server.js",
13
+ "lib/server.es.js"
14
+ ],
12
15
  "repository": {
13
16
  "type": "git",
14
17
  "url": "git@github.com:Tinkoff/tramvai.git"
@@ -23,11 +26,11 @@
23
26
  "@tinkoff/monkeypatch": "1.3.5",
24
27
  "@tinkoff/terminus": "0.0.5",
25
28
  "@tinkoff/url": "0.7.39",
26
- "@tramvai/module-cache-warmup": "2.3.0",
27
- "@tramvai/module-metrics": "2.3.0",
28
- "@tramvai/papi": "2.3.0",
29
- "@tramvai/tokens-server": "2.3.0",
30
- "@tramvai/tokens-server-private": "2.3.0",
29
+ "@tramvai/module-cache-warmup": "2.6.2",
30
+ "@tramvai/module-metrics": "2.6.2",
31
+ "@tramvai/papi": "2.6.2",
32
+ "@tramvai/tokens-server": "2.6.2",
33
+ "@tramvai/tokens-server-private": "2.6.2",
31
34
  "compression": "^1.7.4",
32
35
  "express": "^4.17.1",
33
36
  "fastify": "^3.29.0",
@@ -38,13 +41,13 @@
38
41
  "http-proxy-middleware": "^2.0.2"
39
42
  },
40
43
  "peerDependencies": {
41
- "@tinkoff/dippy": "0.7.43",
44
+ "@tinkoff/dippy": "0.7.44",
42
45
  "@tinkoff/utils": "^2.1.2",
43
- "@tramvai/cli": "2.3.0",
44
- "@tramvai/core": "2.3.0",
45
- "@tramvai/module-common": "2.3.0",
46
- "@tramvai/module-environment": "2.3.0",
47
- "@tramvai/tokens-common": "2.3.0",
46
+ "@tramvai/cli": "2.6.2",
47
+ "@tramvai/core": "2.6.2",
48
+ "@tramvai/module-common": "2.6.2",
49
+ "@tramvai/module-environment": "2.6.2",
50
+ "@tramvai/tokens-common": "2.6.2",
48
51
  "tslib": "^2.0.3"
49
52
  },
50
53
  "devDependencies": {