diff --git a/app.js b/app.js index 258d4fc..fd753df 100644 --- a/app.js +++ b/app.js @@ -1,4 +1,3 @@ -const startTime = Date.now(); import { dirname } from 'node:path'; import { fileURLToPath } from 'node:url'; const __dirname = dirname(fileURLToPath(import.meta.url)); @@ -8,13 +7,13 @@ import app from './src/index.js'; const port = process.env.PORT ? parseInt(process.env.PORT) : 2223; const server = app.listen(port, function () { - console.log(`Start time takes ` + (Date.now() - startTime) / 1000 + ` s`) + console.log(`Start time takes ` + Math.round(process.uptime() * 1000) / 1000 + `s`) console.log(`Listening on ${port} in ${process.env.NODE_ENV} mode`); }) server.on('close', () => { console.log(`Server closing`); setTimeout(() => { - console.log(`Server force closing`); - process.exit(0); + console.log(`Server force closing`); + process.exit(0); }, 2000).unref(); }) diff --git a/src/controllers/unit.js b/src/controllers/unit.js index 44cc19f..0043471 100644 --- a/src/controllers/unit.js +++ b/src/controllers/unit.js @@ -6,14 +6,18 @@ export default function () { var router = express.Router(); router.get('/*', async function (req, res, next) { try { - res.json(JSON.parse((await unitExec.get(req.path)).stdout)); + let result = await unitExec.get(req.path); + res.header("content-type", "application/json") + res.status(200).send(result.stdout); } catch (error) { next(error); } }); router.post('/*', async function (req, res, next) { try { - res.json(JSON.parse((await unitExec.set(req.path, JSON.stringify(req.body))).stdout)); + let result = await unitExec.set(req.path, JSON.stringify(req.body)); + res.header("content-type", "application/json") + res.status(200).send(result.stdout); } catch (error) { next(error); } diff --git a/sudoutil.js b/sudoutil.js index 25edc13..3874f26 100755 --- a/sudoutil.js +++ b/sudoutil.js @@ -140,7 +140,7 @@ switch (cli.args.shift()) { // just in case if (!unit.killed) unit.kill(); - }, 1000 * 60).unref(); + }, 1000 * 600).unref(); break; case 'VIRTUAL_SERVER_GET': arg = cli.args.shift();