From 6613d25d9eea8e72ec67f4a5ea5224813b35f966 Mon Sep 17 00:00:00 2001 From: Jerry Date: Fri, 25 Apr 2025 23:20:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=AF=E7=94=A8http=E5=8E=8B=E7=BC=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 ++ pnpm-lock.yaml | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ src/app.ts | 4 +++- 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 37a12da..16507bd 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "dependencies": { "axios": "^1.8.4", "chalk": "4", + "compression": "^1.8.0", "dotenv": "^16.0.0", "express": "^4.18.0", "ioredis": "^5.6.0", @@ -17,6 +18,7 @@ "ws": "^8.18.1" }, "devDependencies": { + "@types/compression": "^1.7.5", "@types/express": "^4.17.0", "@types/mkdirp": "^2.0.0", "@types/node": "^18.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 77eaf72..8e2b495 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,9 @@ importers: chalk: specifier: '4' version: 4.1.2 + compression: + specifier: ^1.8.0 + version: 1.8.0 dotenv: specifier: ^16.0.0 version: 16.4.7 @@ -33,6 +36,9 @@ importers: specifier: ^8.18.1 version: 8.18.1 devDependencies: + '@types/compression': + specifier: ^1.7.5 + version: 1.7.5 '@types/express': specifier: ^4.17.0 version: 4.17.21 @@ -95,6 +101,9 @@ packages: '@types/body-parser@1.19.5': resolution: {integrity: sha512-fB3Zu92ucau0iQ0JMCFQE7b/dv8Ot07NI3KaZIkIUNXq82k4eBAqUaneXfleGY9JWskeS9y+u0nXMyspcuQrCg==} + '@types/compression@1.7.5': + resolution: {integrity: sha512-AAQvK5pxMpaT+nDvhHrsBhLSYG5yQdtkaJE1WYieSNY2mVFKAgmU4ks65rkZD5oqnGCFLyQpUr1CqI4DmUMyDg==} + '@types/connect@3.4.38': resolution: {integrity: sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==} @@ -227,6 +236,14 @@ packages: resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==} 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: resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} @@ -516,6 +533,10 @@ packages: resolution: {integrity: sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==} engines: {node: '>= 0.6'} + negotiator@0.6.4: + resolution: {integrity: sha512-myRT3DiWPHqho5PrJaIRyaMv2kgYf0mUVgBNOYMuCH5Ki1yEiQaf/ZJuQ62nvpc44wL5WDbTX7yGJi1Neevw8w==} + engines: {node: '>= 0.6'} + normalize-path@3.0.0: resolution: {integrity: sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==} engines: {node: '>=0.10.0'} @@ -528,6 +549,10 @@ packages: resolution: {integrity: sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==} 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: resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==} @@ -789,6 +814,10 @@ snapshots: '@types/connect': 3.4.38 '@types/node': 18.19.86 + '@types/compression@1.7.5': + dependencies: + '@types/express': 4.17.21 + '@types/connect@3.4.38': dependencies: '@types/node': 18.19.86 @@ -949,6 +978,22 @@ snapshots: dependencies: 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: {} content-disposition@0.5.4: @@ -1224,6 +1269,8 @@ snapshots: negotiator@0.6.3: {} + negotiator@0.6.4: {} + normalize-path@3.0.0: {} object-inspect@1.13.4: {} @@ -1232,6 +1279,8 @@ snapshots: dependencies: ee-first: 1.1.1 + on-headers@1.0.2: {} + once@1.4.0: dependencies: wrappy: 1.0.2 diff --git a/src/app.ts b/src/app.ts index 1e55fb5..bb98bbc 100644 --- a/src/app.ts +++ b/src/app.ts @@ -5,6 +5,7 @@ import sampleController from './modules/sample/sample.controller'; import imageController from './modules/image/file.controller'; import config from './utils/core/config'; import './services/ws/wsServer'; +import compression from 'compression'; const apps = { async createApp() { @@ -12,6 +13,7 @@ const apps = { logger.info('晶灵核心初始化..'); app.use(express.json()); + app.use(compression()); logger.debug('成功加载express.json()中间件'); const publicPath = paths.get('public'); @@ -20,7 +22,7 @@ const apps = { const modules = [ { path: '/api/sample', name: '测试模块', controller: sampleController }, - { path: '/files', name: '文件模块', controller: imageController }, + { path: '/public', name: '文件模块', controller: imageController }, ]; modules.forEach((module) => {