Implement json request compression

This commit is contained in:
David Majdandžić
2023-04-01 16:49:50 +02:00
parent 61de0b2a2c
commit af199c9449
4 changed files with 24 additions and 5 deletions

View File

@@ -16,6 +16,7 @@
"nanotimer": "^0.3.15",
"smpp": "^0.6.0-rc.4",
"ts-node": "^10.9.1",
"ws": "^8.13.0"
"ws": "^8.13.0",
"zlib": "^1.0.5"
}
}

View File

@@ -6,6 +6,8 @@ import {RequestHandler} from "./RequestHandler";
const express = require("express");
const bodyParser = require("body-parser");
const compression = require("compression");
const zlib = require("zlib");
const SERVER_PORT: number = Number(process.env.SERVER_PORT) || 8190;
@@ -24,6 +26,11 @@ export class HttpServer {
this.app = express();
this.app.use(bodyParser.json());
this.app.use(compression({
level: 9,
strategy: zlib.constants.BROTLI_MODE_TEXT,
}));
let clientApiPath: string = 'ClientEntity';
let centerApiPath: string = 'CenterEntity';

11
src/ZlibCoder.ts Normal file
View File

@@ -0,0 +1,11 @@
const zlib = require("zlib");
export default class ZlibCoder {
static compress(input: string): Buffer {
return zlib.compress(input);
}
static decompress(input: Buffer): string {
return zlib.decompress(input).toString();
}
}

View File

@@ -29,7 +29,7 @@ function cleanup(): void {
process.exit(0);
}
process.on('exit', cleanup);
process.on('SIGINT', cleanup);
process.on('SIGUSR1', cleanup);
process.on('SIGUSR2', cleanup);
// process.on('exit', cleanup);
// process.on('SIGINT', cleanup);
// process.on('SIGUSR1', cleanup);
// process.on('SIGUSR2', cleanup);