d6327597 by Rafal Wilinski

Added HTTPS support, port deprecated

1 parent 3a5053e5
......@@ -16,8 +16,6 @@ Monitor can be configured by passing options object into `expressMonitor` constr
Default config:
```
path: '/status',
socketPort: 41338, // Port for Socket.io communication,
useHttps: false, // Force HTTPS protocol instead of HTTP
spans: [{
interval: 1, // Every second
retention: 60 // Keep 60 datapoints in memory
......
......@@ -136,7 +136,7 @@
Chart.defaults.global.elements.line.borderColor = "rgba(0,0,0,0.9)";
Chart.defaults.global.elements.line.borderWidth = 2;
var socket = io('{{protocol}}'+ '://' + window.location.hostname + ':{{port}}');
var socket = io(location.protocol + '//' + location.hostname + ':' + location.port);
var defaultSpan = 0;
var spans = [];
......
......@@ -6,11 +6,10 @@
const os = require('os');
const onHeaders = require('on-headers');
const pidusage = require('pidusage');
let io;
const defaultConfig = {
socketPort: 41338,
path: '/status',
useHttps: false,
spans: [{
interval: 1,
retention: 60
......@@ -73,29 +72,17 @@
config.path = defaultConfig.path;
}
if (config.socketPort === undefined || !config instanceof Number) {
config.socketPort = defaultConfig.socketPort;
}
if (config.spans === undefined || !config instanceof Array) {
config.spans = defaultConfig.spans;
}
const io = require('socket.io')(config.socketPort);
fs.readFile(path.join(__dirname, 'index.html'), 'utf8', (err,data) => {
if (err) throw new Error(err);
var result = data.replace(/{{port}}/g, config.socketPort).replace(/{{protocol}}/g, config.useHttps ? 'https' : 'http');
return (req, res, next) => {
if (io === null || io === undefined) {
fs.writeFile(path.join(__dirname, 'index.rendered.html'), result, 'utf8', (err) => {
if (err) throw new Error(err);
});
});
io = require('socket.io')(req.socket.server);
io.on('connection', (socket) => {
socket.emit('start', config.spans);
socket.on('change', function() { socket.emit('start', config.spans); });
});
......@@ -104,11 +91,11 @@
span.responses = [];
setInterval(() => gatherOsMetrics(io, span), span.interval * 1000);
});
}
return (req, res, next) => {
const startTime = process.hrtime();
if (req.path === config.path) {
res.sendFile(path.join(__dirname + '/index.rendered.html'));
res.sendFile(path.join(__dirname + '/index.html'));
} else {
onHeaders(res, () => {
const diff = process.hrtime(startTime);
......
{
"name": "express-status-monitor",
"version": "0.0.8",
"version": "0.0.9",
"description": "Monitoring for Express-based Node applications",
"main": "app.js",
"keywords": [
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!