@tramvai/module-server 2.70.0 → 2.72.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.
Files changed (48) hide show
  1. package/lib/browser.js +2 -31
  2. package/lib/modules/debugRequests.es.js +143 -0
  3. package/lib/modules/debugRequests.js +151 -0
  4. package/lib/modules/dependenciesVersion.es.js +47 -0
  5. package/lib/modules/dependenciesVersion.js +49 -0
  6. package/lib/modules/gracefulShutdown.es.js +104 -0
  7. package/lib/modules/gracefulShutdown.js +106 -0
  8. package/lib/modules/keepAlive.es.js +47 -0
  9. package/lib/modules/keepAlive.js +49 -0
  10. package/lib/modules/papi/api/index.es.js +80 -0
  11. package/lib/modules/papi/api/index.js +88 -0
  12. package/lib/modules/papi/papi.browser.browser.js +13 -0
  13. package/lib/modules/papi/papi.browser.es.js +13 -0
  14. package/lib/modules/papi/papi.browser.js +15 -0
  15. package/lib/modules/papi/papi.es.js +111 -0
  16. package/lib/modules/papi/papi.js +118 -0
  17. package/lib/modules/papi/server/executor.es.js +39 -0
  18. package/lib/modules/papi/server/executor.js +43 -0
  19. package/lib/modules/papi/server/fileApi.es.js +44 -0
  20. package/lib/modules/papi/server/fileApi.js +52 -0
  21. package/lib/modules/papi/shared.browser.js +25 -0
  22. package/lib/modules/papi/shared.es.js +25 -0
  23. package/lib/modules/papi/shared.js +29 -0
  24. package/lib/modules/proxy.es.js +65 -0
  25. package/lib/modules/proxy.js +73 -0
  26. package/lib/modules/serverTiming.es.js +30 -0
  27. package/lib/modules/serverTiming.js +34 -0
  28. package/lib/modules/statics.es.js +48 -0
  29. package/lib/modules/statics.js +54 -0
  30. package/lib/modules/utilityServer.es.js +99 -0
  31. package/lib/modules/utilityServer.js +101 -0
  32. package/lib/modules/utils/require.es.js +11 -0
  33. package/lib/modules/utils/require.js +16 -0
  34. package/lib/modules/utils/tramvaiDepsFilter.es.js +8 -0
  35. package/lib/modules/utils/tramvaiDepsFilter.js +16 -0
  36. package/lib/server/error.es.js +54 -0
  37. package/lib/server/error.js +62 -0
  38. package/lib/server/server.es.js +17 -0
  39. package/lib/server/server.js +26 -0
  40. package/lib/server/static.es.js +34 -0
  41. package/lib/server/static.js +44 -0
  42. package/lib/server/webApp.es.js +103 -0
  43. package/lib/server/webApp.js +113 -0
  44. package/lib/server/xHeaders.es.js +21 -0
  45. package/lib/server/xHeaders.js +30 -0
  46. package/lib/server.es.js +24 -1035
  47. package/lib/server.js +29 -1055
  48. package/package.json +19 -20
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var eachObj = require('@tinkoff/utils/object/each');
6
+ var tokensCommon = require('@tramvai/tokens-common');
7
+ var tokensServer = require('@tramvai/tokens-server');
8
+ var papi = require('@tramvai/papi');
9
+
10
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
+
12
+ var eachObj__default = /*#__PURE__*/_interopDefaultLegacy(eachObj);
13
+
14
+ let papis;
15
+ try {
16
+ // eslint-disable-next-line import/no-extraneous-dependencies
17
+ papis = require('@tramvai/cli/lib/external/api').default; // eslint-disable-line import/no-unresolved
18
+ }
19
+ catch (e) { }
20
+ const getFileApi = ({ logger }) => {
21
+ const log = logger('papi:fileApi');
22
+ const result = [];
23
+ eachObj__default["default"](({ default: entry }, path) => {
24
+ if (!papi.isPapiMethod(entry)) {
25
+ log.error({
26
+ path,
27
+ entry,
28
+ message: `Cannot resolve a papi handler.
29
+ Check that you are using file based papi right way by docs https://tramvai.dev/docs/how-to/how-create-papi#automatic-handler-creation
30
+ 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
31
+ change settings serverApiDir in tramvai.json`,
32
+ });
33
+ throw new Error('Not a papi');
34
+ }
35
+ const papiParameters = papi.getPapiParameters(entry);
36
+ result.push(papi.createPapiMethod({
37
+ ...papiParameters,
38
+ path: `/${path}`,
39
+ }));
40
+ }, papis);
41
+ return result;
42
+ };
43
+ const fileApiProvider = {
44
+ provide: tokensServer.SERVER_MODULE_PAPI_PUBLIC_ROUTE,
45
+ multi: true,
46
+ useFactory: getFileApi,
47
+ deps: {
48
+ logger: tokensCommon.LOGGER_TOKEN,
49
+ },
50
+ };
51
+
52
+ exports.fileApiProvider = fileApiProvider;
@@ -0,0 +1,25 @@
1
+ import { SERVER_MODULE_PAPI_PUBLIC_URL, SERVER_MODULE_PAPI_PRIVATE_URL } from '@tramvai/tokens-server';
2
+ import { APP_INFO_TOKEN } from '@tramvai/core';
3
+
4
+ const sharedProviders = [
5
+ {
6
+ provide: SERVER_MODULE_PAPI_PUBLIC_URL,
7
+ useFactory: ({ appInfo }) => {
8
+ return `/${appInfo.appName}/papi`;
9
+ },
10
+ deps: {
11
+ appInfo: APP_INFO_TOKEN,
12
+ },
13
+ },
14
+ {
15
+ provide: SERVER_MODULE_PAPI_PRIVATE_URL,
16
+ useFactory: ({ appInfo }) => {
17
+ return `/${appInfo.appName}/private/papi`;
18
+ },
19
+ deps: {
20
+ appInfo: APP_INFO_TOKEN,
21
+ },
22
+ },
23
+ ];
24
+
25
+ export { sharedProviders };
@@ -0,0 +1,25 @@
1
+ import { SERVER_MODULE_PAPI_PUBLIC_URL, SERVER_MODULE_PAPI_PRIVATE_URL } from '@tramvai/tokens-server';
2
+ import { APP_INFO_TOKEN } from '@tramvai/core';
3
+
4
+ const sharedProviders = [
5
+ {
6
+ provide: SERVER_MODULE_PAPI_PUBLIC_URL,
7
+ useFactory: ({ appInfo }) => {
8
+ return `/${appInfo.appName}/papi`;
9
+ },
10
+ deps: {
11
+ appInfo: APP_INFO_TOKEN,
12
+ },
13
+ },
14
+ {
15
+ provide: SERVER_MODULE_PAPI_PRIVATE_URL,
16
+ useFactory: ({ appInfo }) => {
17
+ return `/${appInfo.appName}/private/papi`;
18
+ },
19
+ deps: {
20
+ appInfo: APP_INFO_TOKEN,
21
+ },
22
+ },
23
+ ];
24
+
25
+ export { sharedProviders };
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var tokensServer = require('@tramvai/tokens-server');
6
+ var core = require('@tramvai/core');
7
+
8
+ const sharedProviders = [
9
+ {
10
+ provide: tokensServer.SERVER_MODULE_PAPI_PUBLIC_URL,
11
+ useFactory: ({ appInfo }) => {
12
+ return `/${appInfo.appName}/papi`;
13
+ },
14
+ deps: {
15
+ appInfo: core.APP_INFO_TOKEN,
16
+ },
17
+ },
18
+ {
19
+ provide: tokensServer.SERVER_MODULE_PAPI_PRIVATE_URL,
20
+ useFactory: ({ appInfo }) => {
21
+ return `/${appInfo.appName}/private/papi`;
22
+ },
23
+ deps: {
24
+ appInfo: core.APP_INFO_TOKEN,
25
+ },
26
+ },
27
+ ];
28
+
29
+ exports.sharedProviders = sharedProviders;
@@ -0,0 +1,65 @@
1
+ import { __decorate } from 'tslib';
2
+ import eachObj from '@tinkoff/utils/object/each';
3
+ import isArray from '@tinkoff/utils/is/array';
4
+ import isObject from '@tinkoff/utils/is/object';
5
+ import { resolve } from 'path';
6
+ import { Module } from '@tramvai/core';
7
+ import { PROXY_CONFIG_TOKEN } from '@tramvai/tokens-server';
8
+ import { createProxyMiddleware } from 'http-proxy-middleware';
9
+ import { WEB_FASTIFY_APP_INIT_TOKEN } from '@tramvai/tokens-server-private';
10
+ import { safeNodeRequire } from './utils/require.es.js';
11
+
12
+ let ServerProxyModule = class ServerProxyModule {
13
+ };
14
+ ServerProxyModule = __decorate([
15
+ Module({
16
+ providers: [
17
+ {
18
+ provide: WEB_FASTIFY_APP_INIT_TOKEN,
19
+ useFactory: ({ defaultProxies }) => {
20
+ return (app) => {
21
+ const proxyConfig = safeNodeRequire(resolve(process.cwd(), 'proxy.conf'));
22
+ const proxies = defaultProxies !== null && defaultProxies !== void 0 ? defaultProxies : [];
23
+ if (!proxyConfig && proxies.length === 0) {
24
+ return;
25
+ }
26
+ if (isArray(proxyConfig)) {
27
+ proxies.push(...proxyConfig);
28
+ }
29
+ else if (proxyConfig === null || proxyConfig === void 0 ? void 0 : proxyConfig.target) {
30
+ proxies.push(proxyConfig);
31
+ }
32
+ else if (isObject(proxyConfig)) {
33
+ eachObj((target, source) => {
34
+ const options = typeof target === 'string' ? { target } : target;
35
+ proxies.push({ context: source, ...options });
36
+ }, proxyConfig);
37
+ }
38
+ proxies.forEach((proxy) => {
39
+ const middleware = createProxyMiddleware(proxy.context, {
40
+ changeOrigin: true,
41
+ onProxyRes: (proxyRes) => {
42
+ // eslint-disable-next-line no-param-reassign
43
+ proxyRes.headers['x-tramvai-proxied-response'] = '1';
44
+ },
45
+ ...proxy,
46
+ });
47
+ app.addHook('onRequest', (req, res, next) => {
48
+ middleware(req.raw, res.raw, next);
49
+ });
50
+ });
51
+ };
52
+ },
53
+ deps: {
54
+ defaultProxies: {
55
+ token: PROXY_CONFIG_TOKEN,
56
+ optional: true,
57
+ },
58
+ },
59
+ multi: true,
60
+ },
61
+ ],
62
+ })
63
+ ], ServerProxyModule);
64
+
65
+ export { ServerProxyModule };
@@ -0,0 +1,73 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var tslib = require('tslib');
6
+ var eachObj = require('@tinkoff/utils/object/each');
7
+ var isArray = require('@tinkoff/utils/is/array');
8
+ var isObject = require('@tinkoff/utils/is/object');
9
+ var path = require('path');
10
+ var core = require('@tramvai/core');
11
+ var tokensServer = require('@tramvai/tokens-server');
12
+ var httpProxyMiddleware = require('http-proxy-middleware');
13
+ var tokensServerPrivate = require('@tramvai/tokens-server-private');
14
+ var require$1 = require('./utils/require.js');
15
+
16
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
17
+
18
+ var eachObj__default = /*#__PURE__*/_interopDefaultLegacy(eachObj);
19
+ var isArray__default = /*#__PURE__*/_interopDefaultLegacy(isArray);
20
+ var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
21
+
22
+ exports.ServerProxyModule = class ServerProxyModule {
23
+ };
24
+ exports.ServerProxyModule = tslib.__decorate([
25
+ core.Module({
26
+ providers: [
27
+ {
28
+ provide: tokensServerPrivate.WEB_FASTIFY_APP_INIT_TOKEN,
29
+ useFactory: ({ defaultProxies }) => {
30
+ return (app) => {
31
+ const proxyConfig = require$1.safeNodeRequire(path.resolve(process.cwd(), 'proxy.conf'));
32
+ const proxies = defaultProxies !== null && defaultProxies !== void 0 ? defaultProxies : [];
33
+ if (!proxyConfig && proxies.length === 0) {
34
+ return;
35
+ }
36
+ if (isArray__default["default"](proxyConfig)) {
37
+ proxies.push(...proxyConfig);
38
+ }
39
+ else if (proxyConfig === null || proxyConfig === void 0 ? void 0 : proxyConfig.target) {
40
+ proxies.push(proxyConfig);
41
+ }
42
+ else if (isObject__default["default"](proxyConfig)) {
43
+ eachObj__default["default"]((target, source) => {
44
+ const options = typeof target === 'string' ? { target } : target;
45
+ proxies.push({ context: source, ...options });
46
+ }, proxyConfig);
47
+ }
48
+ proxies.forEach((proxy) => {
49
+ const middleware = httpProxyMiddleware.createProxyMiddleware(proxy.context, {
50
+ changeOrigin: true,
51
+ onProxyRes: (proxyRes) => {
52
+ // eslint-disable-next-line no-param-reassign
53
+ proxyRes.headers['x-tramvai-proxied-response'] = '1';
54
+ },
55
+ ...proxy,
56
+ });
57
+ app.addHook('onRequest', (req, res, next) => {
58
+ middleware(req.raw, res.raw, next);
59
+ });
60
+ });
61
+ };
62
+ },
63
+ deps: {
64
+ defaultProxies: {
65
+ token: tokensServer.PROXY_CONFIG_TOKEN,
66
+ optional: true,
67
+ },
68
+ },
69
+ multi: true,
70
+ },
71
+ ],
72
+ })
73
+ ], exports.ServerProxyModule);
@@ -0,0 +1,30 @@
1
+ import { declareModule, provide } from '@tramvai/core';
2
+ import { COMMAND_LINE_EXECUTION_END_TOKEN } from '@tramvai/tokens-core-private';
3
+ import { RESPONSE_MANAGER_TOKEN } from '@tramvai/tokens-common';
4
+
5
+ const ServerTimingModule = declareModule({
6
+ name: 'ServerTiming',
7
+ providers: [
8
+ provide({
9
+ provide: COMMAND_LINE_EXECUTION_END_TOKEN,
10
+ multi: true,
11
+ useValue: (di, type, status, timingInfo) => {
12
+ var _a;
13
+ if (type === 'server' && status === 'customer') {
14
+ const responseManager = di.get(RESPONSE_MANAGER_TOKEN);
15
+ const initialHeader = (_a = responseManager.getHeader('Server-Timing')) !== null && _a !== void 0 ? _a : '';
16
+ const entries = [];
17
+ // index for custom sort
18
+ let index = 0;
19
+ for (const line in timingInfo) {
20
+ const info = timingInfo[line];
21
+ entries.push(`line_${index++}_${line};dur=${info.end - info.start}`);
22
+ }
23
+ responseManager.setHeader('Server-Timing', `${initialHeader ? `${initialHeader}, ` : ''}${entries.join(', ')}`);
24
+ }
25
+ },
26
+ }),
27
+ ],
28
+ });
29
+
30
+ export { ServerTimingModule };
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var core = require('@tramvai/core');
6
+ var tokensCorePrivate = require('@tramvai/tokens-core-private');
7
+ var tokensCommon = require('@tramvai/tokens-common');
8
+
9
+ const ServerTimingModule = core.declareModule({
10
+ name: 'ServerTiming',
11
+ providers: [
12
+ core.provide({
13
+ provide: tokensCorePrivate.COMMAND_LINE_EXECUTION_END_TOKEN,
14
+ multi: true,
15
+ useValue: (di, type, status, timingInfo) => {
16
+ var _a;
17
+ if (type === 'server' && status === 'customer') {
18
+ const responseManager = di.get(tokensCommon.RESPONSE_MANAGER_TOKEN);
19
+ const initialHeader = (_a = responseManager.getHeader('Server-Timing')) !== null && _a !== void 0 ? _a : '';
20
+ const entries = [];
21
+ // index for custom sort
22
+ let index = 0;
23
+ for (const line in timingInfo) {
24
+ const info = timingInfo[line];
25
+ entries.push(`line_${index++}_${line};dur=${info.end - info.start}`);
26
+ }
27
+ responseManager.setHeader('Server-Timing', `${initialHeader ? `${initialHeader}, ` : ''}${entries.join(', ')}`);
28
+ }
29
+ },
30
+ }),
31
+ ],
32
+ });
33
+
34
+ exports.ServerTimingModule = ServerTimingModule;
@@ -0,0 +1,48 @@
1
+ import { __decorate } from 'tslib';
2
+ import { resolve } from 'path';
3
+ import FastifyStatic from '@fastify/static';
4
+ import { Module, provide } from '@tramvai/core';
5
+ import { SERVER_MODULE_STATICS_OPTIONS } from '@tramvai/tokens-server';
6
+ import { WEB_FASTIFY_APP_BEFORE_INIT_TOKEN } from '@tramvai/tokens-server-private';
7
+
8
+ const ONE_YEAR = 365 * 24 * 60 * 60;
9
+ let ServerStaticsModule = class ServerStaticsModule {
10
+ };
11
+ ServerStaticsModule = __decorate([
12
+ Module({
13
+ providers: [
14
+ provide({
15
+ provide: WEB_FASTIFY_APP_BEFORE_INIT_TOKEN,
16
+ useFactory: ({ options }) => {
17
+ const path = (options === null || options === void 0 ? void 0 : options.path) || 'public';
18
+ return (instance) => {
19
+ instance.register(FastifyStatic, {
20
+ decorateReply: false,
21
+ // for backward compatibility, leaving default prefix.
22
+ // without `wildcard: false` property, this middleware has conflicts with express compatibility plugin
23
+ prefix: `/`,
24
+ // prevent errors by use FastifyStatic only for all defined files in the served folder,
25
+ // will not serve the newly added file on the filesystem - https://github.com/fastify/fastify-static#wildcard
26
+ wildcard: false,
27
+ root: resolve(process.cwd(), path),
28
+ setHeaders: (res) => {
29
+ const oneYearForward = new Date(Date.now() + ONE_YEAR * 1000);
30
+ res.setHeader('cache-control', `public, max-age=${ONE_YEAR}`);
31
+ res.setHeader('expires', oneYearForward.toUTCString());
32
+ },
33
+ });
34
+ };
35
+ },
36
+ deps: {
37
+ options: {
38
+ token: SERVER_MODULE_STATICS_OPTIONS,
39
+ optional: true,
40
+ },
41
+ },
42
+ multi: true,
43
+ }),
44
+ ],
45
+ })
46
+ ], ServerStaticsModule);
47
+
48
+ export { ServerStaticsModule };
@@ -0,0 +1,54 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var tslib = require('tslib');
6
+ var path = require('path');
7
+ var FastifyStatic = require('@fastify/static');
8
+ var core = require('@tramvai/core');
9
+ var tokensServer = require('@tramvai/tokens-server');
10
+ var tokensServerPrivate = require('@tramvai/tokens-server-private');
11
+
12
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
+
14
+ var FastifyStatic__default = /*#__PURE__*/_interopDefaultLegacy(FastifyStatic);
15
+
16
+ const ONE_YEAR = 365 * 24 * 60 * 60;
17
+ exports.ServerStaticsModule = class ServerStaticsModule {
18
+ };
19
+ exports.ServerStaticsModule = tslib.__decorate([
20
+ core.Module({
21
+ providers: [
22
+ core.provide({
23
+ provide: tokensServerPrivate.WEB_FASTIFY_APP_BEFORE_INIT_TOKEN,
24
+ useFactory: ({ options }) => {
25
+ const path$1 = (options === null || options === void 0 ? void 0 : options.path) || 'public';
26
+ return (instance) => {
27
+ instance.register(FastifyStatic__default["default"], {
28
+ decorateReply: false,
29
+ // for backward compatibility, leaving default prefix.
30
+ // without `wildcard: false` property, this middleware has conflicts with express compatibility plugin
31
+ prefix: `/`,
32
+ // prevent errors by use FastifyStatic only for all defined files in the served folder,
33
+ // will not serve the newly added file on the filesystem - https://github.com/fastify/fastify-static#wildcard
34
+ wildcard: false,
35
+ root: path.resolve(process.cwd(), path$1),
36
+ setHeaders: (res) => {
37
+ const oneYearForward = new Date(Date.now() + ONE_YEAR * 1000);
38
+ res.setHeader('cache-control', `public, max-age=${ONE_YEAR}`);
39
+ res.setHeader('expires', oneYearForward.toUTCString());
40
+ },
41
+ });
42
+ };
43
+ },
44
+ deps: {
45
+ options: {
46
+ token: tokensServer.SERVER_MODULE_STATICS_OPTIONS,
47
+ optional: true,
48
+ },
49
+ },
50
+ multi: true,
51
+ }),
52
+ ],
53
+ })
54
+ ], exports.ServerStaticsModule);
@@ -0,0 +1,99 @@
1
+ import { __decorate } from 'tslib';
2
+ import { UTILITY_SERVER_PORT_TOKEN, SERVER_TOKEN } from '@tramvai/tokens-server';
3
+ import { UTILITY_SERVER_TOKEN, SERVER_FACTORY_TOKEN, UTILITY_WEB_FASTIFY_APP_TOKEN, WEB_FASTIFY_APP_TOKEN, WEB_FASTIFY_APP_FACTORY_TOKEN } from '@tramvai/tokens-server-private';
4
+ import { ENV_USED_TOKEN, ENV_MANAGER_TOKEN, LOGGER_TOKEN } from '@tramvai/tokens-common';
5
+ import { createToken, Module, provide, Scope, commandLineListTokens } from '@tramvai/core';
6
+
7
+ const IS_CUSTOM_SERVER_TOKEN = createToken('server utility isCustomServer');
8
+ let UtilityServerModule = class UtilityServerModule {
9
+ };
10
+ UtilityServerModule = __decorate([
11
+ Module({
12
+ providers: [
13
+ provide({
14
+ provide: ENV_USED_TOKEN,
15
+ multi: true,
16
+ useValue: [{ key: 'UTILITY_SERVER_PORT', optional: true }],
17
+ }),
18
+ provide({
19
+ provide: UTILITY_SERVER_PORT_TOKEN,
20
+ scope: Scope.SINGLETON,
21
+ useFactory: ({ envManager }) => {
22
+ return +(envManager.get('UTILITY_SERVER_PORT') || envManager.get('PORT'));
23
+ },
24
+ deps: {
25
+ envManager: ENV_MANAGER_TOKEN,
26
+ },
27
+ }),
28
+ provide({
29
+ provide: IS_CUSTOM_SERVER_TOKEN,
30
+ scope: Scope.SINGLETON,
31
+ useFactory: ({ port, envManager }) => {
32
+ return +envManager.get('PORT') !== port;
33
+ },
34
+ deps: {
35
+ envManager: ENV_MANAGER_TOKEN,
36
+ port: UTILITY_SERVER_PORT_TOKEN,
37
+ },
38
+ }),
39
+ provide({
40
+ provide: UTILITY_SERVER_TOKEN,
41
+ scope: Scope.SINGLETON,
42
+ useFactory: ({ isCustomServer, serverFactory, server }) => {
43
+ return isCustomServer ? serverFactory() : server;
44
+ },
45
+ deps: {
46
+ isCustomServer: IS_CUSTOM_SERVER_TOKEN,
47
+ server: SERVER_TOKEN,
48
+ serverFactory: SERVER_FACTORY_TOKEN,
49
+ },
50
+ }),
51
+ provide({
52
+ provide: UTILITY_WEB_FASTIFY_APP_TOKEN,
53
+ scope: Scope.SINGLETON,
54
+ useFactory: ({ isCustomServer, app, appFactory, server }) => {
55
+ return isCustomServer ? appFactory({ server }) : app;
56
+ },
57
+ deps: {
58
+ isCustomServer: IS_CUSTOM_SERVER_TOKEN,
59
+ app: WEB_FASTIFY_APP_TOKEN,
60
+ appFactory: WEB_FASTIFY_APP_FACTORY_TOKEN,
61
+ server: UTILITY_SERVER_TOKEN,
62
+ },
63
+ }),
64
+ provide({
65
+ provide: commandLineListTokens.listen,
66
+ multi: true,
67
+ scope: Scope.SINGLETON,
68
+ useFactory: ({ logger, isCustomServer, port, app, server }) => {
69
+ return async function utilityServerListen() {
70
+ if (!isCustomServer) {
71
+ return;
72
+ }
73
+ const log = logger('server:utility');
74
+ await app.ready();
75
+ return new Promise((resolve, reject) => {
76
+ server.once('error', (error) => {
77
+ log.error({ event: 'server-listen-port', error });
78
+ reject(error);
79
+ });
80
+ server.listen(port, () => {
81
+ log.warn({ event: 'server-listen-port', message: `Server listen ${port} port` });
82
+ resolve();
83
+ });
84
+ });
85
+ };
86
+ },
87
+ deps: {
88
+ logger: LOGGER_TOKEN,
89
+ isCustomServer: IS_CUSTOM_SERVER_TOKEN,
90
+ port: UTILITY_SERVER_PORT_TOKEN,
91
+ app: UTILITY_WEB_FASTIFY_APP_TOKEN,
92
+ server: UTILITY_SERVER_TOKEN,
93
+ },
94
+ }),
95
+ ],
96
+ })
97
+ ], UtilityServerModule);
98
+
99
+ export { UtilityServerModule };
@@ -0,0 +1,101 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var tslib = require('tslib');
6
+ var tokensServer = require('@tramvai/tokens-server');
7
+ var tokensServerPrivate = require('@tramvai/tokens-server-private');
8
+ var tokensCommon = require('@tramvai/tokens-common');
9
+ var core = require('@tramvai/core');
10
+
11
+ const IS_CUSTOM_SERVER_TOKEN = core.createToken('server utility isCustomServer');
12
+ exports.UtilityServerModule = class UtilityServerModule {
13
+ };
14
+ exports.UtilityServerModule = tslib.__decorate([
15
+ core.Module({
16
+ providers: [
17
+ core.provide({
18
+ provide: tokensCommon.ENV_USED_TOKEN,
19
+ multi: true,
20
+ useValue: [{ key: 'UTILITY_SERVER_PORT', optional: true }],
21
+ }),
22
+ core.provide({
23
+ provide: tokensServer.UTILITY_SERVER_PORT_TOKEN,
24
+ scope: core.Scope.SINGLETON,
25
+ useFactory: ({ envManager }) => {
26
+ return +(envManager.get('UTILITY_SERVER_PORT') || envManager.get('PORT'));
27
+ },
28
+ deps: {
29
+ envManager: tokensCommon.ENV_MANAGER_TOKEN,
30
+ },
31
+ }),
32
+ core.provide({
33
+ provide: IS_CUSTOM_SERVER_TOKEN,
34
+ scope: core.Scope.SINGLETON,
35
+ useFactory: ({ port, envManager }) => {
36
+ return +envManager.get('PORT') !== port;
37
+ },
38
+ deps: {
39
+ envManager: tokensCommon.ENV_MANAGER_TOKEN,
40
+ port: tokensServer.UTILITY_SERVER_PORT_TOKEN,
41
+ },
42
+ }),
43
+ core.provide({
44
+ provide: tokensServerPrivate.UTILITY_SERVER_TOKEN,
45
+ scope: core.Scope.SINGLETON,
46
+ useFactory: ({ isCustomServer, serverFactory, server }) => {
47
+ return isCustomServer ? serverFactory() : server;
48
+ },
49
+ deps: {
50
+ isCustomServer: IS_CUSTOM_SERVER_TOKEN,
51
+ server: tokensServer.SERVER_TOKEN,
52
+ serverFactory: tokensServerPrivate.SERVER_FACTORY_TOKEN,
53
+ },
54
+ }),
55
+ core.provide({
56
+ provide: tokensServerPrivate.UTILITY_WEB_FASTIFY_APP_TOKEN,
57
+ scope: core.Scope.SINGLETON,
58
+ useFactory: ({ isCustomServer, app, appFactory, server }) => {
59
+ return isCustomServer ? appFactory({ server }) : app;
60
+ },
61
+ deps: {
62
+ isCustomServer: IS_CUSTOM_SERVER_TOKEN,
63
+ app: tokensServerPrivate.WEB_FASTIFY_APP_TOKEN,
64
+ appFactory: tokensServerPrivate.WEB_FASTIFY_APP_FACTORY_TOKEN,
65
+ server: tokensServerPrivate.UTILITY_SERVER_TOKEN,
66
+ },
67
+ }),
68
+ core.provide({
69
+ provide: core.commandLineListTokens.listen,
70
+ multi: true,
71
+ scope: core.Scope.SINGLETON,
72
+ useFactory: ({ logger, isCustomServer, port, app, server }) => {
73
+ return async function utilityServerListen() {
74
+ if (!isCustomServer) {
75
+ return;
76
+ }
77
+ const log = logger('server:utility');
78
+ await app.ready();
79
+ return new Promise((resolve, reject) => {
80
+ server.once('error', (error) => {
81
+ log.error({ event: 'server-listen-port', error });
82
+ reject(error);
83
+ });
84
+ server.listen(port, () => {
85
+ log.warn({ event: 'server-listen-port', message: `Server listen ${port} port` });
86
+ resolve();
87
+ });
88
+ });
89
+ };
90
+ },
91
+ deps: {
92
+ logger: tokensCommon.LOGGER_TOKEN,
93
+ isCustomServer: IS_CUSTOM_SERVER_TOKEN,
94
+ port: tokensServer.UTILITY_SERVER_PORT_TOKEN,
95
+ app: tokensServerPrivate.UTILITY_WEB_FASTIFY_APP_TOKEN,
96
+ server: tokensServerPrivate.UTILITY_SERVER_TOKEN,
97
+ },
98
+ }),
99
+ ],
100
+ })
101
+ ], exports.UtilityServerModule);
@@ -0,0 +1,11 @@
1
+ const nodeRequire = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require;
2
+ const safeNodeRequire = (path) => {
3
+ try {
4
+ return nodeRequire(path);
5
+ }
6
+ catch (e) {
7
+ return null;
8
+ }
9
+ };
10
+
11
+ export { nodeRequire, safeNodeRequire };
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const nodeRequire = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require;
6
+ const safeNodeRequire = (path) => {
7
+ try {
8
+ return nodeRequire(path);
9
+ }
10
+ catch (e) {
11
+ return null;
12
+ }
13
+ };
14
+
15
+ exports.nodeRequire = nodeRequire;
16
+ exports.safeNodeRequire = safeNodeRequire;