Skip to content

Commit

Permalink
Merge pull request #118 from Terminal-Systems/feature/add-custom-sock…
Browse files Browse the repository at this point in the history
…et-path

Feature - Add custom socket path
  • Loading branch information
RafalWilinski authored Apr 16, 2019
2 parents bd6060d + 98f1ce9 commit 32e0b49
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Default config:
title: 'Express Status', // Default title
theme: 'default.css', // Default styles
path: '/status',
socketPath: '/socket.io', // In case you use a custom path
websocket: existingSocketIoInstance,
spans: [{
interval: 1, // Every second
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
"name": "Jiri Spac",
"email": "[email protected]",
"url": "https://github.com/capaj/"
},
{
"name": "Max Findel",
"email": "[email protected]",
"url": "https://github.com/maxfindel/"
}
],
"repository": {
Expand Down
1 change: 1 addition & 0 deletions src/helpers/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
title: 'Express Status',
theme: 'default.css',
path: '/status',
socketPath: '/socket.io',
spans: [
{
interval: 1,
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ module.exports = config => {

config.title =
typeof config.title === 'string' ? config.title : defaultConfig.title;
config.theme =
typeof config.theme === 'string' ? config.theme : defaultConfig.theme;
config.path =
typeof config.path === 'string' ? config.path : defaultConfig.path;
config.socketPath =
typeof config.socketPath === 'string' ? config.socketPath : defaultConfig.socketPath;
config.spans =
typeof config.spans === 'object' ? config.spans : defaultConfig.spans;
config.port =
Expand Down
1 change: 1 addition & 0 deletions src/middleware-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const middlewareWrapper = config => {
const data = {
title: validatedConfig.title,
port: validatedConfig.port,
socketPath: validatedConfig.socketPath,
bodyClasses: bodyClasses,
script: fs.readFileSync(path.join(__dirname, '/public/javascripts/app.js')),
style: fs.readFileSync(path.join(__dirname, '/public/stylesheets/', validatedConfig.theme))
Expand Down
1 change: 1 addition & 0 deletions src/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ <h1>{{status}}</h1>
</div>
<script>
var port = '{{port}}';
var socketPath = '{{socketPath}}';
{{{script}}}
</script>
</body>
Expand Down
4 changes: 2 additions & 2 deletions src/public/javascripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
eslint-disable no-plusplus, no-var, strict, vars-on-top, prefer-template,
func-names, prefer-arrow-callback, no-loop-func
*/
/* global Chart, location, document, port, parseInt, io */
/* global Chart, location, document, port, socketPath, parseInt, io */

'use strict';

Expand All @@ -13,7 +13,7 @@ Chart.defaults.global.elements.line.backgroundColor = 'rgba(0,0,0,0)';
Chart.defaults.global.elements.line.borderColor = 'rgba(0,0,0,0.9)';
Chart.defaults.global.elements.line.borderWidth = 2;

var socket = io(location.protocol + '//' + location.hostname + ':' + (port || location.port));
var socket = io(location.protocol + '//' + location.hostname + ':' + (port || location.port), { path: socketPath });
var defaultSpan = 0;
var spans = [];
var statusCodesColors = ['#75D701', '#47b8e0', '#ffc952', '#E53A40'];
Expand Down

0 comments on commit 32e0b49

Please sign in to comment.