@tramvai/module-server 1.89.1 → 1.90.4
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/xHeaders.d.ts +2 -2
- package/lib/server.es.js +19 -14
- package/lib/server.js +21 -15
- package/package.json +13 -12
package/lib/server/xHeaders.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { APP_INFO_TOKEN } from '@tramvai/core';
|
|
2
|
-
import type { WEB_APP_TOKEN } from '@tramvai/tokens-server';
|
|
3
2
|
import type { ENV_MANAGER_TOKEN } from '@tramvai/module-common';
|
|
3
|
+
import type { WEB_FASTIFY_APP_TOKEN } from '@tramvai/tokens-server-private';
|
|
4
4
|
export declare const xHeadersFactory: ({ app, envManager, appInfo, }: {
|
|
5
|
-
app: typeof
|
|
5
|
+
app: typeof WEB_FASTIFY_APP_TOKEN;
|
|
6
6
|
envManager: typeof ENV_MANAGER_TOKEN;
|
|
7
7
|
appInfo: typeof APP_INFO_TOKEN;
|
|
8
8
|
}) => () => Promise<void>;
|
package/lib/server.es.js
CHANGED
|
@@ -26,6 +26,8 @@ import toArray from '@tinkoff/utils/array/toArray';
|
|
|
26
26
|
import { create, middlewares, getPapiParameters, createPapiMethod } from '@tramvai/papi';
|
|
27
27
|
import { createChildContainer } from '@tinkoff/dippy';
|
|
28
28
|
import eachObj from '@tinkoff/utils/object/each';
|
|
29
|
+
import { resolve } from 'path';
|
|
30
|
+
import FastifyStatic from 'fastify-static';
|
|
29
31
|
import { createTerminus } from '@tinkoff/terminus';
|
|
30
32
|
import { parse } from '@tinkoff/url';
|
|
31
33
|
import { EventEmitter } from 'events';
|
|
@@ -33,7 +35,6 @@ import monkeypatch from '@tinkoff/monkeypatch';
|
|
|
33
35
|
import https from 'https';
|
|
34
36
|
import isArray from '@tinkoff/utils/is/array';
|
|
35
37
|
import isObject from '@tinkoff/utils/is/object';
|
|
36
|
-
import { resolve } from 'path';
|
|
37
38
|
import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
38
39
|
|
|
39
40
|
const serverFactory = () => {
|
|
@@ -323,9 +324,8 @@ const xHeadersFactory = ({ app, envManager, appInfo, }) => {
|
|
|
323
324
|
'x-deploy-repository': envManager.get('DEPLOY_REPOSITORY'),
|
|
324
325
|
});
|
|
325
326
|
return async () => {
|
|
326
|
-
app.
|
|
327
|
-
|
|
328
|
-
next();
|
|
327
|
+
app.addHook('preHandler', async (_, reply) => {
|
|
328
|
+
reply.headers(xHeaders);
|
|
329
329
|
});
|
|
330
330
|
};
|
|
331
331
|
};
|
|
@@ -534,29 +534,32 @@ let ServerStaticsModule = class ServerStaticsModule {
|
|
|
534
534
|
ServerStaticsModule = __decorate([
|
|
535
535
|
Module({
|
|
536
536
|
providers: [
|
|
537
|
-
{
|
|
538
|
-
provide:
|
|
537
|
+
provide({
|
|
538
|
+
provide: WEB_FASTIFY_APP_BEFORE_INIT_TOKEN,
|
|
539
539
|
useFactory: ({ app, options }) => {
|
|
540
540
|
const path = (options === null || options === void 0 ? void 0 : options.path) || 'public';
|
|
541
541
|
return () => {
|
|
542
|
-
app.
|
|
542
|
+
app.register(FastifyStatic, {
|
|
543
|
+
decorateReply: false,
|
|
544
|
+
prefix: `/${path}`,
|
|
545
|
+
root: resolve(process.cwd(), path),
|
|
543
546
|
setHeaders: (res) => {
|
|
544
547
|
const oneYearForward = new Date(Date.now() + ONE_YEAR * 1000);
|
|
545
|
-
res.
|
|
546
|
-
res.
|
|
548
|
+
res.setHeader('cache-control', `public, max-age=${ONE_YEAR}`);
|
|
549
|
+
res.setHeader('expires', oneYearForward.toUTCString());
|
|
547
550
|
},
|
|
548
|
-
})
|
|
551
|
+
});
|
|
549
552
|
};
|
|
550
553
|
},
|
|
551
554
|
deps: {
|
|
552
|
-
app:
|
|
555
|
+
app: WEB_FASTIFY_APP_TOKEN,
|
|
553
556
|
options: {
|
|
554
557
|
token: SERVER_MODULE_STATICS_OPTIONS,
|
|
555
558
|
optional: true,
|
|
556
559
|
},
|
|
557
560
|
},
|
|
558
561
|
multi: true,
|
|
559
|
-
},
|
|
562
|
+
}),
|
|
560
563
|
],
|
|
561
564
|
})
|
|
562
565
|
], ServerStaticsModule);
|
|
@@ -781,6 +784,8 @@ ServerProxyModule = __decorate([
|
|
|
781
784
|
Module({
|
|
782
785
|
providers: [
|
|
783
786
|
{
|
|
787
|
+
// TODO: tramvai@2 migrate to `fastify` and `fastify-http-proxy`
|
|
788
|
+
// interfaces for the proxies are not compatible so some migration from the app is needed
|
|
784
789
|
provide: WEB_APP_BEFORE_INIT_TOKEN,
|
|
785
790
|
useFactory: ({ app, defaultProxies }) => {
|
|
786
791
|
return () => {
|
|
@@ -969,11 +974,11 @@ ServerModule = __decorate([
|
|
|
969
974
|
],
|
|
970
975
|
},
|
|
971
976
|
{
|
|
972
|
-
provide:
|
|
977
|
+
provide: WEB_FASTIFY_APP_INIT_TOKEN,
|
|
973
978
|
multi: true,
|
|
974
979
|
useFactory: xHeadersFactory,
|
|
975
980
|
deps: {
|
|
976
|
-
app:
|
|
981
|
+
app: WEB_FASTIFY_APP_TOKEN,
|
|
977
982
|
envManager: ENV_MANAGER_TOKEN,
|
|
978
983
|
appInfo: APP_INFO_TOKEN,
|
|
979
984
|
},
|
package/lib/server.js
CHANGED
|
@@ -29,6 +29,8 @@ var toArray = require('@tinkoff/utils/array/toArray');
|
|
|
29
29
|
var papi = require('@tramvai/papi');
|
|
30
30
|
var dippy = require('@tinkoff/dippy');
|
|
31
31
|
var eachObj = require('@tinkoff/utils/object/each');
|
|
32
|
+
var path = require('path');
|
|
33
|
+
var FastifyStatic = require('fastify-static');
|
|
32
34
|
var terminus = require('@tinkoff/terminus');
|
|
33
35
|
var url = require('@tinkoff/url');
|
|
34
36
|
var events = require('events');
|
|
@@ -36,7 +38,6 @@ var monkeypatch = require('@tinkoff/monkeypatch');
|
|
|
36
38
|
var https = require('https');
|
|
37
39
|
var isArray = require('@tinkoff/utils/is/array');
|
|
38
40
|
var isObject = require('@tinkoff/utils/is/object');
|
|
39
|
-
var path = require('path');
|
|
40
41
|
var httpProxyMiddleware = require('http-proxy-middleware');
|
|
41
42
|
|
|
42
43
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -57,6 +58,7 @@ var filterObj__default = /*#__PURE__*/_interopDefaultLegacy(filterObj);
|
|
|
57
58
|
var flatten__default = /*#__PURE__*/_interopDefaultLegacy(flatten);
|
|
58
59
|
var toArray__default = /*#__PURE__*/_interopDefaultLegacy(toArray);
|
|
59
60
|
var eachObj__default = /*#__PURE__*/_interopDefaultLegacy(eachObj);
|
|
61
|
+
var FastifyStatic__default = /*#__PURE__*/_interopDefaultLegacy(FastifyStatic);
|
|
60
62
|
var monkeypatch__default = /*#__PURE__*/_interopDefaultLegacy(monkeypatch);
|
|
61
63
|
var https__default = /*#__PURE__*/_interopDefaultLegacy(https);
|
|
62
64
|
var isArray__default = /*#__PURE__*/_interopDefaultLegacy(isArray);
|
|
@@ -349,9 +351,8 @@ const xHeadersFactory = ({ app, envManager, appInfo, }) => {
|
|
|
349
351
|
'x-deploy-repository': envManager.get('DEPLOY_REPOSITORY'),
|
|
350
352
|
});
|
|
351
353
|
return async () => {
|
|
352
|
-
app.
|
|
353
|
-
|
|
354
|
-
next();
|
|
354
|
+
app.addHook('preHandler', async (_, reply) => {
|
|
355
|
+
reply.headers(xHeaders);
|
|
355
356
|
});
|
|
356
357
|
};
|
|
357
358
|
};
|
|
@@ -560,29 +561,32 @@ let ServerStaticsModule = class ServerStaticsModule {
|
|
|
560
561
|
ServerStaticsModule = tslib.__decorate([
|
|
561
562
|
core.Module({
|
|
562
563
|
providers: [
|
|
563
|
-
{
|
|
564
|
-
provide:
|
|
564
|
+
core.provide({
|
|
565
|
+
provide: tokensServerPrivate.WEB_FASTIFY_APP_BEFORE_INIT_TOKEN,
|
|
565
566
|
useFactory: ({ app, options }) => {
|
|
566
|
-
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';
|
|
567
568
|
return () => {
|
|
568
|
-
app.
|
|
569
|
+
app.register(FastifyStatic__default["default"], {
|
|
570
|
+
decorateReply: false,
|
|
571
|
+
prefix: `/${path$1}`,
|
|
572
|
+
root: path.resolve(process.cwd(), path$1),
|
|
569
573
|
setHeaders: (res) => {
|
|
570
574
|
const oneYearForward = new Date(Date.now() + ONE_YEAR * 1000);
|
|
571
|
-
res.
|
|
572
|
-
res.
|
|
575
|
+
res.setHeader('cache-control', `public, max-age=${ONE_YEAR}`);
|
|
576
|
+
res.setHeader('expires', oneYearForward.toUTCString());
|
|
573
577
|
},
|
|
574
|
-
})
|
|
578
|
+
});
|
|
575
579
|
};
|
|
576
580
|
},
|
|
577
581
|
deps: {
|
|
578
|
-
app:
|
|
582
|
+
app: tokensServerPrivate.WEB_FASTIFY_APP_TOKEN,
|
|
579
583
|
options: {
|
|
580
584
|
token: tokensServer.SERVER_MODULE_STATICS_OPTIONS,
|
|
581
585
|
optional: true,
|
|
582
586
|
},
|
|
583
587
|
},
|
|
584
588
|
multi: true,
|
|
585
|
-
},
|
|
589
|
+
}),
|
|
586
590
|
],
|
|
587
591
|
})
|
|
588
592
|
], ServerStaticsModule);
|
|
@@ -807,6 +811,8 @@ ServerProxyModule = tslib.__decorate([
|
|
|
807
811
|
core.Module({
|
|
808
812
|
providers: [
|
|
809
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
|
|
810
816
|
provide: tokensServer.WEB_APP_BEFORE_INIT_TOKEN,
|
|
811
817
|
useFactory: ({ app, defaultProxies }) => {
|
|
812
818
|
return () => {
|
|
@@ -995,11 +1001,11 @@ exports.ServerModule = tslib.__decorate([
|
|
|
995
1001
|
],
|
|
996
1002
|
},
|
|
997
1003
|
{
|
|
998
|
-
provide:
|
|
1004
|
+
provide: tokensServerPrivate.WEB_FASTIFY_APP_INIT_TOKEN,
|
|
999
1005
|
multi: true,
|
|
1000
1006
|
useFactory: xHeadersFactory,
|
|
1001
1007
|
deps: {
|
|
1002
|
-
app:
|
|
1008
|
+
app: tokensServerPrivate.WEB_FASTIFY_APP_TOKEN,
|
|
1003
1009
|
envManager: tokensCommon.ENV_MANAGER_TOKEN,
|
|
1004
1010
|
appInfo: core.APP_INFO_TOKEN,
|
|
1005
1011
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/module-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.90.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"browser": "lib/browser.js",
|
|
6
6
|
"main": "lib/server.js",
|
|
@@ -20,14 +20,14 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@tinkoff/errors": "0.2.20",
|
|
23
|
-
"@tinkoff/terminus": "0.0.1",
|
|
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.
|
|
27
|
-
"@tramvai/module-metrics": "1.
|
|
28
|
-
"@tramvai/papi": "1.
|
|
29
|
-
"@tramvai/tokens-server": "1.
|
|
30
|
-
"@tramvai/tokens-server-private": "1.
|
|
26
|
+
"@tramvai/module-cache-warmup": "1.90.4",
|
|
27
|
+
"@tramvai/module-metrics": "1.90.4",
|
|
28
|
+
"@tramvai/papi": "1.90.4",
|
|
29
|
+
"@tramvai/tokens-server": "1.90.4",
|
|
30
|
+
"@tramvai/tokens-server-private": "1.90.4",
|
|
31
31
|
"body-parser": "^1.19.0",
|
|
32
32
|
"compression": "^1.7.4",
|
|
33
33
|
"cookie-parser": "^1.4.3",
|
|
@@ -36,16 +36,17 @@
|
|
|
36
36
|
"fastify-cookie": "^5.6.0",
|
|
37
37
|
"fastify-formbody": "^5.2.0",
|
|
38
38
|
"fastify-plugin": "^3.0.1",
|
|
39
|
+
"fastify-static": "^4.6.1",
|
|
39
40
|
"http-proxy-middleware": "^2.0.2"
|
|
40
41
|
},
|
|
41
42
|
"peerDependencies": {
|
|
42
43
|
"@tinkoff/dippy": "0.7.39",
|
|
43
44
|
"@tinkoff/utils": "^2.1.2",
|
|
44
|
-
"@tramvai/cli": "1.
|
|
45
|
-
"@tramvai/core": "1.
|
|
46
|
-
"@tramvai/module-common": "1.
|
|
47
|
-
"@tramvai/module-environment": "1.
|
|
48
|
-
"@tramvai/tokens-common": "1.
|
|
45
|
+
"@tramvai/cli": "1.90.4",
|
|
46
|
+
"@tramvai/core": "1.90.4",
|
|
47
|
+
"@tramvai/module-common": "1.90.4",
|
|
48
|
+
"@tramvai/module-environment": "1.90.4",
|
|
49
|
+
"@tramvai/tokens-common": "1.90.4",
|
|
49
50
|
"tslib": "^2.0.3"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|