Skip to content

Commit c7ec191

Browse files
feat: add express compression
1 parent 946741e commit c7ec191

File tree

8 files changed

+3297
-3267
lines changed

8 files changed

+3297
-3267
lines changed

package-lock.json

Lines changed: 3252 additions & 3235 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
"worker",
1515
"typescript"
1616
],
17-
"publishConfig": {
18-
"access": "public"
19-
},
20-
"repository": {
17+
"publishConfig": {
18+
"access": "public"
19+
},
20+
"repository": {
2121
"type": "git",
2222
"url": "https://github.com/Lomray-Software/microservice-nodejs-lib.git"
2323
},
@@ -38,18 +38,20 @@
3838
"prepare": "husky install"
3939
},
4040
"dependencies": {
41-
"axios": "^0.24.0",
42-
"express": "^4.17.2",
41+
"axios": "^0.27.2",
42+
"compression": "^1.7.4",
43+
"express": "^4.18.1",
4344
"lodash": "^4.17.21",
44-
"uuid": "^8.3.2"
45+
"uuid": "^9.0.0"
4546
},
4647
"devDependencies": {
47-
"@commitlint/cli": "^13.2.1",
48-
"@commitlint/config-conventional": "^13.2.0",
48+
"@commitlint/cli": "^17.1.2",
49+
"@commitlint/config-conventional": "^17.1.0",
4950
"@istanbuljs/nyc-config-typescript": "^1.0.2",
50-
"@lomray/eslint-config": "^1.1.2",
51-
"@lomray/prettier-config": "^1.1.0",
51+
"@lomray/eslint-config": "^1.2.1",
52+
"@lomray/prettier-config": "^1.2.0",
5253
"@types/chai": "^4.3.0",
54+
"@types/compression": "^1.7.2",
5355
"@types/express": "^4.17.13",
5456
"@types/lodash": "^4.14.178",
5557
"@types/mocha": "^9.0.0",
@@ -58,23 +60,23 @@
5860
"@types/sinon-chai": "^3.2.8",
5961
"@types/uuid": "^8.3.4",
6062
"@zerollup/ts-transform-paths": "^1.7.18",
61-
"rollup-plugin-ts": "^2.0.5",
62-
"chai": "^4.3.4",
63+
"chai": "^4.3.6",
6364
"eslint": "^7.32.0",
6465
"eslint-config-prettier": "^8.3.0",
6566
"eslint-plugin-prettier": "^4.0.0",
66-
"husky": "^7.0.4",
67-
"lint-staged": "^11.2.6",
68-
"mocha": "^9.1.3",
67+
"husky": "^8.0.1",
68+
"lint-staged": "^13.0.3",
69+
"mocha": "^9.2.2",
6970
"nyc": "^15.1.0",
70-
"prettier": "^2.5.1",
71-
"rollup": "^2.63.0",
72-
"semantic-release": "^18.0.1",
73-
"sinon": "^11.1.2",
71+
"prettier": "^2.7.1",
72+
"rollup": "^2.79.1",
73+
"rollup-plugin-ts": "^2.0.7",
74+
"semantic-release": "^19.0.5",
75+
"sinon": "^14.0.0",
7476
"sinon-chai": "^3.7.0",
75-
"ts-node": "^10.4.0",
76-
"tsconfig-paths": "^3.12.0",
77+
"ts-node": "10.9.1",
78+
"tsconfig-paths": "^3.14.1",
7779
"ttypescript": "^1.5.13",
78-
"typescript": "4.4.4"
80+
"typescript": "4.7.4"
7981
}
8082
}

src/drivers/console-log.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
LOG_INFO_COLOR,
66
LOG_INTERNAL_COLOR,
77
} from '@constants/index';
8-
import { LogType, ConsoleInfoType } from '@interfaces/drivers/console-log';
8+
import type { ConsoleInfoType } from '@interfaces/drivers/console-log';
9+
import { LogType } from '@interfaces/drivers/console-log';
910

1011
const reqIds = new Map();
1112

src/interfaces/core/i-microservice-response.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { CookieOptions } from 'express-serve-static-core';
2-
import BaseException from '@core/base-exception';
2+
import type BaseException from '@core/base-exception';
33

44
enum CookiesAction {
55
add = 'add',

src/interfaces/services/i-abstract-microservice.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import type { AxiosRequestConfig, AxiosResponse } from 'axios';
22
import type { Request } from 'express';
3-
import MicroserviceRequest from '@core/microservice-request';
4-
import MicroserviceResponse from '@core/microservice-response';
3+
import type MicroserviceRequest from '@core/microservice-request';
4+
import type MicroserviceResponse from '@core/microservice-response';
55
import type { IEventRequest } from '@interfaces/core/i-event-request';
66
import type { IMicroserviceRequest } from '@interfaces/core/i-microservice-request';
77
import type {
88
IMicroserviceResponseResult,
99
IMicroserviceResponse,
1010
} from '@interfaces/core/i-microservice-response';
1111
import type { LogDriverType } from '@interfaces/drivers/console-log';
12-
import AbstractMicroservice from '@services/abstract-microservice';
12+
import type AbstractMicroservice from '@services/abstract-microservice';
1313

1414
interface IAbstractMicroserviceOptions {
1515
name: string;

src/interfaces/services/i-gateway.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { OptionsJson } from 'body-parser';
2+
import type { CompressionOptions } from 'compression';
23
import type { Express, Request } from 'express';
34
import type { IMicroserviceRequest } from '@interfaces/core/i-microservice-request';
45
import type {
@@ -14,6 +15,7 @@ interface IGatewayOptions extends IAbstractMicroserviceOptions {
1415
hasAutoRegistration: boolean;
1516
batchLimit: number;
1617
jsonParams: OptionsJson;
18+
compressionOptions?: CompressionOptions | false;
1719
}
1820

1921
interface IGatewayParams extends IAbstractMicroserviceParams {

src/services/abstract-microservice.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import WaitSec from '@helpers/wait-sec';
1414
import type IBaseException from '@interfaces/core/i-base-exception';
1515
import type { IEventRequest } from '@interfaces/core/i-event-request';
1616
import type { IMicroserviceRequest } from '@interfaces/core/i-microservice-request';
17-
import { LogDriverType, LogType } from '@interfaces/drivers/console-log';
17+
import type { LogDriverType } from '@interfaces/drivers/console-log';
18+
import { LogType } from '@interfaces/drivers/console-log';
1819
import type {
1920
IAbstractMicroserviceOptions,
2021
IAbstractMicroserviceParams,

src/services/gateway.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
import compression from 'compression';
12
import type { Express, Request, Response } from 'express';
23
import express from 'express';
3-
import { NextFunction } from 'express-serve-static-core';
4+
import type { NextFunction } from 'express-serve-static-core';
45
import _ from 'lodash';
56
import { EXCEPTION_CODE } from '@constants/index';
67
import BaseException from '@core/base-exception';
78
import MicroserviceRequest from '@core/microservice-request';
89
import MicroserviceResponse from '@core/microservice-response';
910
import { LogType } from '@interfaces/drivers/console-log';
1011
import { MiddlewareType } from '@interfaces/services/i-abstract-microservice';
11-
import {
12+
import type {
1213
GatewayEndpointHandler,
1314
IExpressRequest,
1415
IGatewayOptions,
@@ -69,10 +70,16 @@ class Gateway extends AbstractMicroservice {
6970
this.init(options, params);
7071

7172
const { beforeRoute, afterRoute } = params;
72-
const { listener, jsonParams } = this.options;
73+
const { listener, jsonParams, compressionOptions } = this.options;
7374
const [, ...route] = listener.split('/');
7475

7576
this.express.disable('x-powered-by');
77+
78+
// Enable response compression
79+
if (compressionOptions !== false) {
80+
this.express.use(compression(compressionOptions));
81+
}
82+
7683
// Parse JSON body request
7784
this.express.use(express.json(jsonParams));
7885
beforeRoute?.(this.express);

0 commit comments

Comments
 (0)