-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom serve-static equivalent Remove rewrites, colors, update snap
- Loading branch information
Ram Lmn
committed
Feb 15, 2018
1 parent
7d90a49
commit 7d0155a
Showing
17 changed files
with
796 additions
and
2,045 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 |
---|---|---|
|
@@ -32,4 +32,4 @@ | |
"valid-jsdoc": 0, | ||
"arrow-parens": 0 | ||
} | ||
} | ||
} |
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,3 +1,2 @@ | ||
node_modules | ||
test | ||
*.log | ||
*.log |
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 @@ | ||
package-lock=false |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict'; | ||
|
||
const crypto = require('crypto'); | ||
|
||
const addEtag = (req, res, next) => { | ||
const data = []; | ||
|
||
req.on('data', chunk => { | ||
data.push(chunk); | ||
}); | ||
|
||
req.on('end', _ => { | ||
const body = Buffer.concat(data); | ||
const etag = crypto.createHash('sha1') | ||
.update(body) | ||
.digest('hex'); | ||
|
||
res.setHeader('ETag', etag); | ||
|
||
next(); | ||
}); | ||
}; | ||
|
||
module.exports = addEtag; |
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,26 @@ | ||
'use strict'; | ||
|
||
|
||
const HTTPSRedirect = (req, res, next) => { | ||
if (req.hostname === 'localhost') { | ||
return next(); | ||
} | ||
|
||
// For non-localhost hosts, check the header for the protocol used. | ||
if (!req.headers['x-forwarded-proto']) { | ||
return next(); | ||
} | ||
|
||
if ((req.headers['x-forwarded-proto'] || '').toLowerCase() === 'http') { | ||
// reason for the redirect | ||
res.setHeader('Non-Authoritative-Reason', 'HSTS'); | ||
|
||
// internal (temporary) redirect | ||
return res.redirect(307, `https://${req.hostname}${req.url}`); | ||
} | ||
|
||
return next(); | ||
}; | ||
|
||
|
||
module.exports = HTTPSRedirect; |
Oops, something went wrong.