Skip to content

Commit

Permalink
Return an error page for the blocked users. Changed the returned stat…
Browse files Browse the repository at this point in the history
…us code from 429 to 403. This is to better reflect the functionality of a blocklist rather than rate limiting which 429 implies.

Signed-off-by: Michael Cinkus <[email protected]>
  • Loading branch information
Spunkie committed Feb 23, 2017
1 parent 51690bc commit bf9c9d0
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ const testHandler = (req, res) => {
// Abort if user is blocked
if (blockList.indexOf(req.params.user) !== -1) {
ErrorHandler.log(`Request blocked for user ${req.params.user}`)

const template = require(__dirname + '/templates/blocklist.status.js')
const blockListTemplate = template(req)

return res.status(429).send()
return res.status(blockListTemplate.statusCode).send(blockListTemplate.body)
}

const speedtracker = new SpeedTracker({
Expand Down
57 changes: 57 additions & 0 deletions templates/blocklist.status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const utils = require(__dirname + '/../lib/utils')

const blocklist = (req) => {
const body = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>403 Forbidden!</title>
<style>
header {
width: 100%;
height: 100px;
background-color: #CB4C3D;
color: white;
text-align: center;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
code {
font-weight: bold;
font-style: italic;
background-color: #EFF0F1;
}
</style>
</head>
<body>
<main>
<header>
<h1>ERROR 403 - Forbidden!</h1>
</header>
<section>
<h2>The following error occurrred:</h2>
<p>Requests for user <code>${req.params.user}</code> are blocked.</p>
<hr>
<p>If you believe this is an error or would like to dispute this block then contact: <a href="mailto:[email protected]">[email protected]</a></p>
</section>
</main>
</body>
</html>
`

return {
body,
statusCode: 403
}
}

module.exports = blocklist

0 comments on commit bf9c9d0

Please sign in to comment.