pm2 live logs
This commit is contained in:
1 parent
0b9be294c2
commit
ec38d0245a
4 files changed
+69
-4
No files matched your search
@@ -4,6 +4,9 @@ const express = require('express');
|
||||
const path = require('path');
|
||||
const morgan = require('morgan');
|
||||
const bodyParser = require('body-parser');
|
||||
const http = require('http');
|
||||
const WebSocket = require('ws');
|
||||
const { spawn } = require('child_process');
|
||||
|
||||
const indexRouter = require('./routes/index');
|
||||
|
||||
@@ -24,7 +27,6 @@ app.use(bodyParser.json());
|
||||
// skip: (req) => req.url.startsWith('/assets') || req.url.startsWith('/favicon.ico')
|
||||
// }));
|
||||
|
||||
|
||||
// Routes
|
||||
app.use('/', indexRouter);
|
||||
|
||||
@@ -37,6 +39,29 @@ app.use((err, req, res, next) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.listen(PORT, () =>
|
||||
// -----------------------------
|
||||
// Wrap Express in HTTP + WS
|
||||
// -----------------------------
|
||||
const server = http.createServer(app);
|
||||
const wss = new WebSocket.Server({ server });
|
||||
|
||||
// When a client connects, stream PM2 logs
|
||||
wss.on('connection', ws => {
|
||||
const pm2Logs = spawn('pm2', ['logs', '--json']);
|
||||
|
||||
pm2Logs.stdout.on('data', data => {
|
||||
ws.send(data.toString());
|
||||
});
|
||||
|
||||
pm2Logs.stderr.on('data', data => {
|
||||
ws.send('ERROR: ' + data.toString());
|
||||
});
|
||||
|
||||
ws.on('close', () => {
|
||||
pm2Logs.kill();
|
||||
});
|
||||
});
|
||||
|
||||
server.listen(PORT, () =>
|
||||
console.log(`Proxer-Downloader running on http://localhost:${PORT}`)
|
||||
);
|
||||
Reference in new issue
Block a user