diff --git a/.env.example b/.env.example index 82e94f4e..2fe81775 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,4 @@ +PUBLIC_PORT=5400 CRON_PORT=5500 BACK_PORT=5600 PORT=5700 diff --git a/back/config/index.ts b/back/config/index.ts index 44d062ea..6a87b762 100644 --- a/back/config/index.ts +++ b/back/config/index.ts @@ -37,6 +37,7 @@ if (envFound.error) { export default { port: parseInt(process.env.BACK_PORT as string, 10), cronPort: parseInt(process.env.CRON_PORT as string, 10), + publicPort: parseInt(process.env.PUBLIC_PORT as string, 10), secret: process.env.SECRET || createRandomString(16, 32), logs: { level: process.env.LOG_LEVEL || 'silly', diff --git a/back/public.ts b/back/public.ts new file mode 100644 index 00000000..b4cef216 --- /dev/null +++ b/back/public.ts @@ -0,0 +1,34 @@ +import express from 'express'; +import { exec } from 'child_process'; +import Logger from './loaders/logger'; +import config from './config'; + +const app = express(); + +const run = async () => { + app.get('/api/public/panel/log', (req, res) => { + exec('pm2 logs panel --lines 500', (err, stdout, stderr) => { + if (err || stderr) { + return res.send({ code: 400, data: err || stderr }); + } + return res.send({ code: 200, data: stdout }); + }); + }); +}; + +app + .listen(config.publicPort, async () => { + await require('./loaders/sentry').default({ expressApp: app }); + await require('./loaders/db').default(); + + await run(); + Logger.info(` + ################################################ + 🛡️ Public listening on port: ${config.publicPort} 🛡️ + ################################################ + `); + }) + .on('error', (err) => { + Logger.error(err); + process.exit(1); + }); diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index e852e637..0d44e8eb 100755 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -20,24 +20,29 @@ echo -e "======================3. 启动nginx========================\n" nginx -s reload 2>/dev/null || nginx -c /etc/nginx/nginx.conf echo -e "nginx启动成功...\n" -echo -e "======================4. 启动控制面板========================\n" +echo -e "======================4. 启动面板监控========================\n" +pm2 delete public &>/dev/null +pm2 start $dir_static/build/public.js -n public --source-map-support --time +echo -e "监控服务启动成功...\n" + +echo -e "======================5. 启动控制面板========================\n" pm2 delete panel &>/dev/null pm2 start $dir_static/build/app.js -n panel --source-map-support --time echo -e "控制面板启动成功...\n" -echo -e "======================5. 启动定时任务========================\n" +echo -e "======================6. 启动定时任务========================\n" pm2 delete schedule &>/dev/null pm2 start $dir_static/build/schedule.js -n schedule --source-map-support --time echo -e "定时任务启动成功...\n" if [[ $AutoStartBot == true ]]; then - echo -e "======================6. 启动bot========================\n" + echo -e "======================7. 启动bot========================\n" nohup ql bot >>$dir_log/start.log 2>&1 & echo -e "bot后台启动中...\n" fi if [[ $EnableExtraShell == true ]]; then - echo -e "======================7. 执行自定义脚本========================\n" + echo -e "======================8. 执行自定义脚本========================\n" nohup ql extra >>$dir_log/start.log 2>&1 & echo -e "自定义脚本后台执行中...\n" fi diff --git a/docker/front.conf b/docker/front.conf index ee894c21..052aff8a 100644 --- a/docker/front.conf +++ b/docker/front.conf @@ -2,6 +2,10 @@ upstream api { server 0.0.0.0:5600; } +upstream public { + server 0.0.0.0:5400; +} + map $http_upgrade $connection_upgrade { default keep-alive; 'websocket' upgrade; @@ -12,6 +16,13 @@ server { root /ql/static/dist; ssl_session_timeout 5m; + location /api/public { + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_pass http://public; + } + location /api { proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr;