Skip to content

Commit

Permalink
Merge pull request #50 from mattiaerre/codebase-reorg
Browse files Browse the repository at this point in the history
codebase reorganization
  • Loading branch information
RafalWilinski authored Sep 9, 2016
2 parents 2003a4f + 21406af commit 20c3f12
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 45 deletions.
2 changes: 1 addition & 1 deletion license.txt → LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MIT License
The MIT License (MIT)

Copyright (c) 2016 Rafal Wilinski

Expand Down
32 changes: 1 addition & 31 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,31 +1 @@
const fs = require('fs');
const path = require('path');
const onHeaders = require('on-headers');
const validate = require('./helpers/validate');
const onHeadersListener = require('./helpers/on-headers-listener');
const socketIoInit = require('./helpers/socket-io-init');

const middlewareWrapper = (config) => {
config = validate(config);

const renderedHtml =
fs.readFileSync(path.join(__dirname, '/index.html'))
.toString()
.replace(/{{title}}/g, config.title)
.replace(/{{script}}/g, fs.readFileSync(path.join(__dirname, '/app.js')))
.replace(/{{style}}/g, fs.readFileSync(path.join(__dirname, '/style.css')));

return (req, res, next) => {
socketIoInit(req.socket.server, config.spans);

const startTime = process.hrtime();
if (req.path === config.path) {
res.send(renderedHtml);
} else {
onHeaders(res, () => { onHeadersListener(res.statusCode, startTime, config.spans) });
next();
}
};
};

module.exports = middlewareWrapper;
module.exports = require('./src/middleware-wrapper');
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"express",
"charts"
],
"engines" : {
"node" : ">=4"
"engines": {
"node": ">=4"
},
"author": "Rafal Wilinski <[email protected]> (http://rwilinski.me)",
"contributors": [
Expand Down Expand Up @@ -56,4 +56,4 @@
"mocha": "^3.0.2",
"sinon": "^1.17.5"
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
31 changes: 31 additions & 0 deletions src/middleware-wrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const fs = require('fs');
const path = require('path');
const onHeaders = require('on-headers');
const validate = require('./helpers/validate');
const onHeadersListener = require('./helpers/on-headers-listener');
const socketIoInit = require('./helpers/socket-io-init');

const middlewareWrapper = (config) => {
config = validate(config);

const renderedHtml =
fs.readFileSync(path.join(__dirname, '/public/index.html'))
.toString()
.replace(/{{title}}/g, config.title)
.replace(/{{script}}/g, fs.readFileSync(path.join(__dirname, '/public/javascripts/app.js')))
.replace(/{{style}}/g, fs.readFileSync(path.join(__dirname, '/public/stylesheets/style.css')));

return (req, res, next) => {
socketIoInit(req.socket.server, config.spans);

const startTime = process.hrtime();
if (req.path === config.path) {
res.send(renderedHtml);
} else {
onHeaders(res, () => { onHeadersListener(res.statusCode, startTime, config.spans) });
next();
}
};
};

module.exports = middlewareWrapper;
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/helpers/gather-os-metrics.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const chai = require('chai');

chai.should();

const gatherOsMetrics = require('../../helpers/gather-os-metrics');
const gatherOsMetrics = require('../../src/helpers/gather-os-metrics');

describe('helpers', () => {
describe('gather-os-metrics', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/on-headers-listener.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const sinon = require('sinon');

chai.should();

const onHeadersListener = require('../../helpers/on-headers-listener');
const defaultConfig = require('../../helpers/default-config');
const onHeadersListener = require('../../src/helpers/on-headers-listener');
const defaultConfig = require('../../src/helpers/default-config');

describe('helpers', () => {
describe('on-headers-listener', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/send-metrics.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const sinon = require('sinon');

chai.should();

const sendMetrics = require('../../helpers/send-metrics');
const sendMetrics = require('../../src/helpers/send-metrics');

describe('helpers', () => {
describe('send-metrics', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/socket-io-init.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const chai = require('chai');

chai.should();

const socketIoInit = require('../../helpers/socket-io-init');
const defaultConfig = require('../../helpers/default-config');
const socketIoInit = require('../../src/helpers/socket-io-init');
const defaultConfig = require('../../src/helpers/default-config');

describe('helpers', () => {
describe('socket-io-init', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/validate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const chai = require('chai');

chai.should();

const defaultConfig = require('../../helpers/default-config');
const validate = require('../../helpers/validate');
const defaultConfig = require('../../src/helpers/default-config');
const validate = require('../../src/helpers/validate');

describe('helpers', () => {
describe('validate', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/index.spec.js → test/middleware-wrapper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const sinon = require('sinon');

chai.should();

const expresStatusMonitor = require('../index');
const defaultConfig = require('../helpers/default-config');
const expresStatusMonitor = require('../src/middleware-wrapper');
const defaultConfig = require('../src/helpers/default-config');

describe('express-status-monitor', () => {
describe('when initialised', () => {
Expand Down

0 comments on commit 20c3f12

Please sign in to comment.