From 8b8bd279c605d7425f83880cceb37cd0304a19b8 Mon Sep 17 00:00:00 2001 From: whyour Date: Thu, 4 May 2023 21:28:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20nginx=20=E8=BD=AC=E5=8F=91?= =?UTF-8?q?stream=E6=8E=A5=E5=8F=A3=E5=A4=B1=E6=95=88=EF=BC=8C=E5=81=9C?= =?UTF-8?q?=E6=AD=A2=E8=BF=90=E8=A1=8C=E5=91=BD=E4=BB=A4=E6=94=AF=E6=8C=81?= =?UTF-8?q?=20pid=20=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/api/system.ts | 6 +++++- back/loaders/express.ts | 3 ++- back/services/system.ts | 17 +++++++++++++---- docker/front.conf | 3 +++ 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/back/api/system.ts b/back/api/system.ts index 57df89da..2bea5493 100644 --- a/back/api/system.ts +++ b/back/api/system.ts @@ -170,6 +170,9 @@ export default (app: Router) => { await systemService.run( { ...req.body, logPath }, { + onStart: async (cp, startTime) => { + res.setHeader('QL-Task-Pid', `${cp.pid}`); + }, onEnd: async (cp, endTime, diff) => { res.end(); }, @@ -195,7 +198,8 @@ export default (app: Router) => { '/command-stop', celebrate({ body: Joi.object({ - command: Joi.string().required(), + command: Joi.string().optional(), + pid: Joi.number().optional(), }), }), async (req: Request, res: Response, next: NextFunction) => { diff --git a/back/loaders/express.ts b/back/loaders/express.ts index a514eb31..29dbd74b 100644 --- a/back/loaders/express.ts +++ b/back/loaders/express.ts @@ -14,6 +14,7 @@ import handler from 'serve-handler'; import * as Sentry from '@sentry/node'; import { EnvModel } from '../data/env'; import { errors } from 'celebrate'; +import path from 'path'; export default ({ app }: { app: Application }) => { app.enable('trust proxy'); @@ -25,7 +26,7 @@ export default ({ app }: { app: Application }) => { next(); } else { return handler(req, res, { - public: 'static/dist', + public: path.join(config.rootPath, 'static/dist'), rewrites: [{ source: '**', destination: '/index.html' }], }); } diff --git a/back/services/system.ts b/back/services/system.ts index 9a34bf53..d1be3ccf 100644 --- a/back/services/system.ts +++ b/back/services/system.ts @@ -190,13 +190,22 @@ export default class SystemService { ); } - public async stop({ command }: { command: string }) { + public async stop({ command, pid }: { command: string; pid: number }) { + if (!pid && !command) { + return { code: 400, message: '参数错误' }; + } + + if (pid) { + await killTask(pid); + return { code: 200 }; + } + if (!command.startsWith(TASK_COMMAND)) { command = `${TASK_COMMAND} ${command}`; } - const pid = await getPid(command); - if (pid) { - await killTask(pid); + const _pid = await getPid(command); + if (_pid) { + await killTask(_pid); return { code: 200 }; } else { return { code: 400, message: '任务未找到' }; diff --git a/docker/front.conf b/docker/front.conf index dddcbeef..e9bac9fc 100644 --- a/docker/front.conf +++ b/docker/front.conf @@ -22,6 +22,7 @@ server { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://publicApi/api/; + proxy_buffering off; } location QL_BASE_URL/api/ { @@ -29,6 +30,7 @@ server { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://baseApi/api/; + proxy_buffering off; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; @@ -39,6 +41,7 @@ server { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://baseApi/open/; + proxy_buffering off; } gzip on;