mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-22 22:36:06 +08:00
修复 nginx 转发stream接口失效,停止运行命令支持 pid 参数
This commit is contained in:
parent
01b404765e
commit
8b8bd279c6
|
@ -170,6 +170,9 @@ export default (app: Router) => {
|
||||||
await systemService.run(
|
await systemService.run(
|
||||||
{ ...req.body, logPath },
|
{ ...req.body, logPath },
|
||||||
{
|
{
|
||||||
|
onStart: async (cp, startTime) => {
|
||||||
|
res.setHeader('QL-Task-Pid', `${cp.pid}`);
|
||||||
|
},
|
||||||
onEnd: async (cp, endTime, diff) => {
|
onEnd: async (cp, endTime, diff) => {
|
||||||
res.end();
|
res.end();
|
||||||
},
|
},
|
||||||
|
@ -195,7 +198,8 @@ export default (app: Router) => {
|
||||||
'/command-stop',
|
'/command-stop',
|
||||||
celebrate({
|
celebrate({
|
||||||
body: Joi.object({
|
body: Joi.object({
|
||||||
command: Joi.string().required(),
|
command: Joi.string().optional(),
|
||||||
|
pid: Joi.number().optional(),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
async (req: Request, res: Response, next: NextFunction) => {
|
async (req: Request, res: Response, next: NextFunction) => {
|
||||||
|
|
|
@ -14,6 +14,7 @@ import handler from 'serve-handler';
|
||||||
import * as Sentry from '@sentry/node';
|
import * as Sentry from '@sentry/node';
|
||||||
import { EnvModel } from '../data/env';
|
import { EnvModel } from '../data/env';
|
||||||
import { errors } from 'celebrate';
|
import { errors } from 'celebrate';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
export default ({ app }: { app: Application }) => {
|
export default ({ app }: { app: Application }) => {
|
||||||
app.enable('trust proxy');
|
app.enable('trust proxy');
|
||||||
|
@ -25,7 +26,7 @@ export default ({ app }: { app: Application }) => {
|
||||||
next();
|
next();
|
||||||
} else {
|
} else {
|
||||||
return handler(req, res, {
|
return handler(req, res, {
|
||||||
public: 'static/dist',
|
public: path.join(config.rootPath, 'static/dist'),
|
||||||
rewrites: [{ source: '**', destination: '/index.html' }],
|
rewrites: [{ source: '**', destination: '/index.html' }],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)) {
|
if (!command.startsWith(TASK_COMMAND)) {
|
||||||
command = `${TASK_COMMAND} ${command}`;
|
command = `${TASK_COMMAND} ${command}`;
|
||||||
}
|
}
|
||||||
const pid = await getPid(command);
|
const _pid = await getPid(command);
|
||||||
if (pid) {
|
if (_pid) {
|
||||||
await killTask(pid);
|
await killTask(_pid);
|
||||||
return { code: 200 };
|
return { code: 200 };
|
||||||
} else {
|
} else {
|
||||||
return { code: 400, message: '任务未找到' };
|
return { code: 400, message: '任务未找到' };
|
||||||
|
|
|
@ -22,6 +22,7 @@ server {
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
proxy_pass http://publicApi/api/;
|
proxy_pass http://publicApi/api/;
|
||||||
|
proxy_buffering off;
|
||||||
}
|
}
|
||||||
|
|
||||||
location QL_BASE_URL/api/ {
|
location QL_BASE_URL/api/ {
|
||||||
|
@ -29,6 +30,7 @@ server {
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
proxy_pass http://baseApi/api/;
|
proxy_pass http://baseApi/api/;
|
||||||
|
proxy_buffering off;
|
||||||
|
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
proxy_set_header Connection $connection_upgrade;
|
proxy_set_header Connection $connection_upgrade;
|
||||||
|
@ -39,6 +41,7 @@ server {
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
proxy_pass http://baseApi/open/;
|
proxy_pass http://baseApi/open/;
|
||||||
|
proxy_buffering off;
|
||||||
}
|
}
|
||||||
|
|
||||||
gzip on;
|
gzip on;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user