This commit is contained in:
gangwen.lv 2023-07-17 22:14:31 +08:00
parent 410fcb017e
commit 0c96d7c69e
4 changed files with 2 additions and 152 deletions

View File

@ -14,8 +14,6 @@ services:
volumes: volumes:
- /home/xiaoyh/node2/schoolfellow:/fellow - /home/xiaoyh/node2/schoolfellow:/fellow
- /home/xiaoyh/node2/schoolfellow/logs:/home/node/logs - /home/xiaoyh/node2/schoolfellow/logs:/home/node/logs
# - ./package/fellow.json:/fellow/package.json:ro
# - ./patch/gzip.js:/fellow/app/middleware/gzip.js
working_dir: /fellow working_dir: /fellow
# command: /bin/sh -c "while true; do echo hello world; sleep 1;done" # command: /bin/sh -c "while true; do echo hello world; sleep 1;done"
command: npm run start-docker command: npm run start-docker
@ -35,8 +33,6 @@ services:
volumes: volumes:
- /home/xiaoyh/node2/jjh-server:/foundation - /home/xiaoyh/node2/jjh-server:/foundation
- /home/xiaoyh/node2/jjh-server/logs:/home/node/logs - /home/xiaoyh/node2/jjh-server/logs:/home/node/logs
# - ./package/foundation.json:/foundation/package.json:ro
# - ./patch/gzip.js:/foundation/app/middleware/gzip.js
working_dir: /foundation working_dir: /foundation
command: npm run start-docker command: npm run start-docker
ports: ports:

View File

@ -1,56 +0,0 @@
{
"name": "schoolefellow-server",
"version": "1.0.0",
"description": "后台管理系统api",
"private": true,
"egg": {
"declarations": true
},
"dependencies": {
"egg": "^2.15.1",
"egg-bcrypt": "^1.1.0",
"egg-cors": "^2.2.3",
"egg-scripts": "^2.11.0",
"egg-sequelize": "^6.0.0",
"egg-validate-plus": "^1.1.6",
"jsonwebtoken": "^8.5.1",
"mysql2": "^2.2.5",
"svg-captcha": "^1.4.0"
},
"devDependencies": {
"autod": "^3.0.1",
"autod-egg": "^1.1.0",
"egg-bin": "^4.11.0",
"egg-ci": "^1.11.0",
"egg-mock": "^3.21.0",
"eslint": "^5.13.0",
"eslint-config-egg": "^7.1.0",
"sequelize-cli": "^6.2.0"
},
"engines": {
"node": ">=10.0.0"
},
"scripts": {
"start": "egg-scripts start --daemon --title=egg-server-cms-api --ignore-stderr",
"start-docker": "egg-scripts start --title=egg-server-cms-api --ignore-stderr",
"stop": "egg-scripts stop --title=egg-server-cms-api",
"dev": "egg-bin dev",
"debug": "egg-bin debug",
"test": "npm run lint -- --fix && npm run test-local",
"test-local": "egg-bin test",
"cov": "egg-bin cov",
"lint": "eslint .",
"ci": "npm run lint && npm run cov",
"autod": "autod"
},
"ci": {
"version": "10"
},
"repository": {
"type": "git",
"url": ""
},
"author": "gaoxiangan",
"license": "MIT"
}

View File

@ -1,55 +0,0 @@
{
"name": "schoolefellow-server",
"version": "1.0.0",
"description": "后台管理系统api",
"private": true,
"egg": {
"declarations": true
},
"dependencies": {
"egg": "^2.15.1",
"egg-bcrypt": "^1.1.0",
"egg-cors": "^2.2.3",
"egg-scripts": "^2.11.0",
"egg-sequelize": "^6.0.0",
"egg-validate-plus": "^1.1.6",
"jsonwebtoken": "^8.5.1",
"mysql2": "^2.2.5",
"svg-captcha": "^1.4.0"
},
"devDependencies": {
"autod": "^3.0.1",
"autod-egg": "^1.1.0",
"egg-bin": "^4.11.0",
"egg-ci": "^1.11.0",
"egg-mock": "^3.21.0",
"eslint": "^5.13.0",
"eslint-config-egg": "^7.1.0",
"sequelize-cli": "^6.2.0"
},
"engines": {
"node": ">=10.0.0"
},
"scripts": {
"start": "egg-scripts start --daemon --title=egg-server-cms-api --ignore-stderr",
"start-docker": "egg-scripts start --title=egg-server-cms-api --ignore-stderr",
"stop": "egg-scripts stop --title=egg-server-cms-api",
"dev": "egg-bin dev",
"debug": "egg-bin debug",
"test": "npm run lint -- --fix && npm run test-local",
"test-local": "egg-bin test",
"cov": "egg-bin cov",
"lint": "eslint .",
"ci": "npm run lint && npm run cov",
"autod": "autod"
},
"ci": {
"version": "10"
},
"repository": {
"type": "git",
"url": ""
},
"author": "gaoxiangan",
"license": "MIT"
}

View File

@ -1,35 +0,0 @@
const isJSON = require("koa-is-json");
const zlib = require("zlib");
module.exports = (options) => {
return async function gzip(ctx, next) {
// 限制域名访问 added by steven @2023-07-11
const ipCheck = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;
const host = ctx.request.host.indexOf(":")
? ctx.request.host.split(":")[0]
: ctx.request.host;
if (ipCheck.test(host)) {
ctx.status = 200;
ctx.body = `<!DOCTYPE html><html><head><title>访问禁止</title></head><body>只允许域名方式访问</body></html>`;
// ctx.throw(401, "只允许域名访问");
return;
}
/////
await next();
// 后续中间件执行完成后将响应体转换成 gzip
let body = ctx.body;
if (!body) return;
// 支持 options.threshold
if (options.threshold && ctx.length < options.threshold) return;
if (isJSON(body)) body = JSON.stringify(body);
// 设置 gzip body修正响应头
const stream = zlib.createGzip();
stream.end(body);
ctx.body = stream;
ctx.set("Content-Encoding", "gzip");
};
};