增加public服务,查询panel日志

This commit is contained in:
whyour
2022-02-24 23:50:04 +08:00
parent 531fc48bdf
commit ee52f09bcb
5 changed files with 56 additions and 4 deletions
+1
View File
@@ -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',
+34
View File
@@ -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);
});