init
This commit is contained in:
commit
91a12cc98e
8
Dockerfile
Normal file
8
Dockerfile
Normal file
@ -0,0 +1,8 @@
|
||||
FROM node:16-alpine
|
||||
|
||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
|
||||
apk --update add tzdata && \
|
||||
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
|
||||
echo "Asia/Shanghai" > /etc/timezone && \
|
||||
apk del tzdata && \
|
||||
rm -rf /var/cache/apk/*
|
43
docker-compose.yml
Normal file
43
docker-compose.yml
Normal file
@ -0,0 +1,43 @@
|
||||
version: "3.5"
|
||||
|
||||
services:
|
||||
fellow:
|
||||
image: node:16-alpine-cn
|
||||
build: .
|
||||
hostname: fellow
|
||||
container_name: fellow
|
||||
network_mode: host
|
||||
privileged: true
|
||||
restart: always
|
||||
environment:
|
||||
- MOCK_HOME_DIR=/fellow
|
||||
volumes:
|
||||
- /home/xiaoyh/node/schoolfellow:/fellow
|
||||
- /home/xiaoyh/node/schoolfellow/logs:/home/node/logs
|
||||
- ./package/fellow.json:/fellow/package.json:ro
|
||||
- ./patch/gzip.js:/fellow/app/middleware/gzip.js
|
||||
working_dir: /fellow
|
||||
# command: /bin/sh -c "while true; do echo hello world; sleep 1;done"
|
||||
command: npm run start-docker
|
||||
ports:
|
||||
- "7001:7001"
|
||||
|
||||
foundation:
|
||||
image: node:16-alpine-cn
|
||||
build: .
|
||||
hostname: foundation
|
||||
container_name: foundation
|
||||
network_mode: host
|
||||
privileged: true
|
||||
restart: always
|
||||
environment:
|
||||
- MOCK_HOME_DIR=/foundation
|
||||
volumes:
|
||||
- /home/xiaoyh/node/jjh-server:/foundation
|
||||
- /home/xiaoyh/node/jjh-server/logs:/home/node/logs
|
||||
- ./package/foundation.json:/foundation/package.json:ro
|
||||
- ./patch/gzip.js:/foundation/app/middleware/gzip.js
|
||||
working_dir: /foundation
|
||||
command: npm run start-docker
|
||||
ports:
|
||||
- "7002:7002"
|
56
package/fellow.json
Normal file
56
package/fellow.json
Normal file
@ -0,0 +1,56 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
|
55
package/foundation.json
Normal file
55
package/foundation.json
Normal file
@ -0,0 +1,55 @@
|
||||
{
|
||||
"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"
|
||||
}
|
35
patch/gzip.js
Normal file
35
patch/gzip.js
Normal file
@ -0,0 +1,35 @@
|
||||
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");
|
||||
};
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user