From c8284197ccb84a7ccecf85e990232bf05ef40500 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Thu, 25 Oct 2018 11:26:55 +0100 Subject: [PATCH] Fix #140 by using URL prefix passed in as part of options (#165) * Fix #140 by using URL prefix passed in as part of options * Update AUTHORS.md --- AUTHORS.md | 1 + lib/appmetrics-dash.js | 4 ++-- public/index.html | 10 ++++------ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/AUTHORS.md b/AUTHORS.md index 1fe0022..1f64f51 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -16,3 +16,4 @@ Authors ordered by first contribution: - Vajahath Ahmed (https://github.com/vajahath) - Jonathan Spruce (https://github.com/jonathan-spruce) - Andreas Opferkuch (https://github.com/s-h-a-d-o-w) + - Alex Potsides (https://github.com/achingbrain) diff --git a/lib/appmetrics-dash.js b/lib/appmetrics-dash.js index 8118731..bdefe3f 100644 --- a/lib/appmetrics-dash.js +++ b/lib/appmetrics-dash.js @@ -145,7 +145,7 @@ exports.monitor = function(options) { var app = express(); server = require('http').Server(app); // Specify a path, to not collide with user's socket.io. - io = require('socket.io')(server, { path: '/appmetrics-dash/socket.io' }); + io = require('socket.io')(server, { path: url + '/socket.io' }); app.use(middleware); @@ -168,7 +168,7 @@ exports.monitor = function(options) { // Don't patch socket.io, it already knows to ignore requests that are not // its own. debug('listen for socket.io'); - io = require('socket.io')(server, { path: '/appmetrics-dash/socket.io' }); + io = require('socket.io')(server, { path: url + '/socket.io' }); debug('patch new request listeners...'); server.on('newListener', function(eventName, listener) { diff --git a/public/index.html b/public/index.html index 36ceb96..dd3763b 100644 --- a/public/index.html +++ b/public/index.html @@ -29,7 +29,7 @@ - + @@ -165,12 +165,10 @@ tallerGraphHeight = canvasHeight - margin.top - margin.shortBottom, graphHeight = canvasHeight - margin.top - margin.bottom; - let hostname = location.host; - let pathname = location.pathname // User may have requested appmetrics-dash/index.html - let dashboardRoot = "/" + pathname.split('/')[1]; + let dashboardRoot = location.pathname.split('index.html')[0] || '/'; - var socket = io.connect(hostname, { path: '/appmetrics-dash/socket.io' }); + var socket = io.connect(location.host, { path: dashboardRoot + 'socket.io' }); function getTimeFormat() { var currentTime = new Date() @@ -206,7 +204,7 @@