diff --git a/back/loaders/express.ts b/back/loaders/express.ts index 4cdd7f12..92714249 100644 --- a/back/loaders/express.ts +++ b/back/loaders/express.ts @@ -30,6 +30,13 @@ export default ({ app }: { app: Application }) => { if (!headerToken && req.path && req.path === '/api/login') { return next(); } + const remoteAddress = req.socket.remoteAddress; + if ( + remoteAddress === '::ffff:127.0.0.1' && + req.path === '/api/crons/status' + ) { + return next(); + } const err: any = new Error('UnauthorizedError'); err['status'] = 401; next(err); diff --git a/back/services/cron.ts b/back/services/cron.ts index fbccceaf..23fc0941 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -211,18 +211,17 @@ export default class CronService { cmdStr = `${cmdStr} now`; } - const cp = spawn(cmdStr, { shell: true, detached: true }); - this.cronDb.update( - { _id }, - { $set: { status: CrontabStatus.running, pid: cp.pid } }, - ); - cp.on('close', (code) => { + const cp = exec(cmdStr, (err, stdout, stderr) => { this.cronDb.update( { _id }, { $set: { status: CrontabStatus.idle }, $unset: { pid: true } }, ); resolve(); }); + this.cronDb.update( + { _id }, + { $set: { status: CrontabStatus.running, pid: cp.pid } }, + ); }); }