启用http压缩

This commit is contained in:
Jerry 2025-04-25 23:20:51 +08:00
parent 7ffdeca847
commit 6613d25d9e
3 changed files with 54 additions and 1 deletions

View File

@ -9,6 +9,7 @@
"dependencies": { "dependencies": {
"axios": "^1.8.4", "axios": "^1.8.4",
"chalk": "4", "chalk": "4",
"compression": "^1.8.0",
"dotenv": "^16.0.0", "dotenv": "^16.0.0",
"express": "^4.18.0", "express": "^4.18.0",
"ioredis": "^5.6.0", "ioredis": "^5.6.0",
@ -17,6 +18,7 @@
"ws": "^8.18.1" "ws": "^8.18.1"
}, },
"devDependencies": { "devDependencies": {
"@types/compression": "^1.7.5",
"@types/express": "^4.17.0", "@types/express": "^4.17.0",
"@types/mkdirp": "^2.0.0", "@types/mkdirp": "^2.0.0",
"@types/node": "^18.0.0", "@types/node": "^18.0.0",

49
pnpm-lock.yaml generated
View File

@ -14,6 +14,9 @@ importers:
chalk: chalk:
specifier: '4' specifier: '4'
version: 4.1.2 version: 4.1.2
compression:
specifier: ^1.8.0
version: 1.8.0
dotenv: dotenv:
specifier: ^16.0.0 specifier: ^16.0.0
version: 16.4.7 version: 16.4.7
@ -33,6 +36,9 @@ importers:
specifier: ^8.18.1 specifier: ^8.18.1
version: 8.18.1 version: 8.18.1
devDependencies: devDependencies:
'@types/compression':
specifier: ^1.7.5
version: 1.7.5
'@types/express': '@types/express':
specifier: ^4.17.0 specifier: ^4.17.0
version: 4.17.21 version: 4.17.21
@ -95,6 +101,9 @@ packages:
'@types/body-parser@1.19.5': '@types/body-parser@1.19.5':
resolution: {integrity: sha512-fB3Zu92ucau0iQ0JMCFQE7b/dv8Ot07NI3KaZIkIUNXq82k4eBAqUaneXfleGY9JWskeS9y+u0nXMyspcuQrCg==} resolution: {integrity: sha512-fB3Zu92ucau0iQ0JMCFQE7b/dv8Ot07NI3KaZIkIUNXq82k4eBAqUaneXfleGY9JWskeS9y+u0nXMyspcuQrCg==}
'@types/compression@1.7.5':
resolution: {integrity: sha512-AAQvK5pxMpaT+nDvhHrsBhLSYG5yQdtkaJE1WYieSNY2mVFKAgmU4ks65rkZD5oqnGCFLyQpUr1CqI4DmUMyDg==}
'@types/connect@3.4.38': '@types/connect@3.4.38':
resolution: {integrity: sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==} resolution: {integrity: sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==}
@ -227,6 +236,14 @@ packages:
resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==} resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==}
engines: {node: '>= 0.8'} engines: {node: '>= 0.8'}
compressible@2.0.18:
resolution: {integrity: sha512-AF3r7P5dWxL8MxyITRMlORQNaOA2IkAFaTr4k7BUumjPtRpGDTZpl0Pb1XCO6JeDCBdp126Cgs9sMxqSjgYyRg==}
engines: {node: '>= 0.6'}
compression@1.8.0:
resolution: {integrity: sha512-k6WLKfunuqCYD3t6AsuPGvQWaKwuLLh2/xHNcX4qE+vIfDNXpSqnrhwA7O53R7WVQUnt8dVAIW+YHr7xTgOgGA==}
engines: {node: '>= 0.8.0'}
concat-map@0.0.1: concat-map@0.0.1:
resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==}
@ -516,6 +533,10 @@ packages:
resolution: {integrity: sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==} resolution: {integrity: sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==}
engines: {node: '>= 0.6'} engines: {node: '>= 0.6'}
negotiator@0.6.4:
resolution: {integrity: sha512-myRT3DiWPHqho5PrJaIRyaMv2kgYf0mUVgBNOYMuCH5Ki1yEiQaf/ZJuQ62nvpc44wL5WDbTX7yGJi1Neevw8w==}
engines: {node: '>= 0.6'}
normalize-path@3.0.0: normalize-path@3.0.0:
resolution: {integrity: sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==} resolution: {integrity: sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==}
engines: {node: '>=0.10.0'} engines: {node: '>=0.10.0'}
@ -528,6 +549,10 @@ packages:
resolution: {integrity: sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==} resolution: {integrity: sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==}
engines: {node: '>= 0.8'} engines: {node: '>= 0.8'}
on-headers@1.0.2:
resolution: {integrity: sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA==}
engines: {node: '>= 0.8'}
once@1.4.0: once@1.4.0:
resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==} resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==}
@ -789,6 +814,10 @@ snapshots:
'@types/connect': 3.4.38 '@types/connect': 3.4.38
'@types/node': 18.19.86 '@types/node': 18.19.86
'@types/compression@1.7.5':
dependencies:
'@types/express': 4.17.21
'@types/connect@3.4.38': '@types/connect@3.4.38':
dependencies: dependencies:
'@types/node': 18.19.86 '@types/node': 18.19.86
@ -949,6 +978,22 @@ snapshots:
dependencies: dependencies:
delayed-stream: 1.0.0 delayed-stream: 1.0.0
compressible@2.0.18:
dependencies:
mime-db: 1.52.0
compression@1.8.0:
dependencies:
bytes: 3.1.2
compressible: 2.0.18
debug: 2.6.9
negotiator: 0.6.4
on-headers: 1.0.2
safe-buffer: 5.2.1
vary: 1.1.2
transitivePeerDependencies:
- supports-color
concat-map@0.0.1: {} concat-map@0.0.1: {}
content-disposition@0.5.4: content-disposition@0.5.4:
@ -1224,6 +1269,8 @@ snapshots:
negotiator@0.6.3: {} negotiator@0.6.3: {}
negotiator@0.6.4: {}
normalize-path@3.0.0: {} normalize-path@3.0.0: {}
object-inspect@1.13.4: {} object-inspect@1.13.4: {}
@ -1232,6 +1279,8 @@ snapshots:
dependencies: dependencies:
ee-first: 1.1.1 ee-first: 1.1.1
on-headers@1.0.2: {}
once@1.4.0: once@1.4.0:
dependencies: dependencies:
wrappy: 1.0.2 wrappy: 1.0.2

View File

@ -5,6 +5,7 @@ import sampleController from './modules/sample/sample.controller';
import imageController from './modules/image/file.controller'; import imageController from './modules/image/file.controller';
import config from './utils/core/config'; import config from './utils/core/config';
import './services/ws/wsServer'; import './services/ws/wsServer';
import compression from 'compression';
const apps = { const apps = {
async createApp() { async createApp() {
@ -12,6 +13,7 @@ const apps = {
logger.info('晶灵核心初始化..'); logger.info('晶灵核心初始化..');
app.use(express.json()); app.use(express.json());
app.use(compression());
logger.debug('成功加载express.json()中间件'); logger.debug('成功加载express.json()中间件');
const publicPath = paths.get('public'); const publicPath = paths.get('public');
@ -20,7 +22,7 @@ const apps = {
const modules = [ const modules = [
{ path: '/api/sample', name: '测试模块', controller: sampleController }, { path: '/api/sample', name: '测试模块', controller: sampleController },
{ path: '/files', name: '文件模块', controller: imageController }, { path: '/public', name: '文件模块', controller: imageController },
]; ];
modules.forEach((module) => { modules.forEach((module) => {