Skip to content

Commit 0a2bc88

Browse files
authored
Merge pull request #66 from Hydrock/feature/base-tag
2 parents ae5f2e6 + eb52d31 commit 0a2bc88

File tree

7 files changed

+3009
-3063
lines changed

7 files changed

+3009
-3063
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ Default options:
5353

5454
```js
5555
title: 'hapi.js Status',
56-
path: '/status',
56+
path: '/status', // Path to Status Page
57+
base: '/', // href attribute of the base html tag
5758
websocket: null, // The Socket.io instance to be used, if none provided a new one will be created!
5859
spans: [{
5960
interval: 1, // Every second

__tests__/helpers/default-config.spec.js

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ describe('helpers', () => {
1111
expect('/status').toEqual(defaultConfig.path);
1212
});
1313

14+
it('then base === /', () => {
15+
expect('/').toEqual(defaultConfig.base);
16+
});
17+
18+
1419
it('then spans === array', () => {
1520
const spans = [
1621
{ interval: 1, retention: 60, responses: [] },

src/helpers/default-config.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = {
22
title: 'hapi.js Status',
33
path: '/status',
4+
base: '/',
45
spans: [
56
{
67
interval: 1,

src/middleware-wrapper.js

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const middlewareWrapper = (server, options) => {
2020
const renderedHtml = fs.readFileSync(path.join(__dirname, '/public/index.html'))
2121
.toString()
2222
.replace(/{{title}}/g, opts.title)
23+
.replace(/{{base}}/g, opts.base)
2324
.replace(/{{script}}/g, fs.readFileSync(path.join(__dirname, '/public/javascripts/app.js')))
2425
.replace(/{{style}}/g, fs.readFileSync(path.join(__dirname, '/public/stylesheets/style.css')));
2526

src/public/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4+
<base href="{{base}}">
45
<title>{{title}}</title>
56
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.bundle.min.js"></script>
67
<script src="https://cdn.socket.io/4.5.0/socket.io.min.js"></script>

src/public/javascripts/app.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ Chart.defaults.global.elements.line.backgroundColor = "rgba(0,0,0,0)";
77
Chart.defaults.global.elements.line.borderColor = "rgba(0,0,0,0.9)";
88
Chart.defaults.global.elements.line.borderWidth = 2;
99

10-
var socket = io(location.protocol + '//' + location.hostname + ':' + location.port);
10+
const baseTag = document.querySelector('base');
11+
const basePath = baseTag ? baseTag.getAttribute('href') : '/';
12+
13+
var socket = io(location.protocol + '//' + location.hostname + ':' + location.port, {
14+
path: `${basePath}/socket.io`
15+
});
1116
var defaultSpan = 0;
1217
var spans = [];
1318
var statusCodesColors = ['#75D701', '#47b8e0', '#ffc952', '#E53A40'];

yarn.lock

+2,993-3,061
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)