Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return an error page for the blocked users. More relevant http status code. #22

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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