-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from mattiaerre/codebase-reorg
codebase reorganization
- Loading branch information
Showing
19 changed files
with
46 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,8 @@ | |
"express", | ||
"charts" | ||
], | ||
"engines" : { | ||
"node" : ">=4" | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"author": "Rafal Wilinski <[email protected]> (http://rwilinski.me)", | ||
"contributors": [ | ||
|
@@ -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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters