Skip to content

Commit e3fd6c6

Browse files
committed
Return an error page for the blocked users. Changed the returned status code from 429 to 403. This is to better reflect the functionality of a blocklist rather than rate limiting which 429 implies. Rebase to fix git author.
Signed-off-by: Spunkie <github@spunkiedesign.com>
1 parent 51690bc commit e3fd6c6

2 files changed

Lines changed: 61 additions & 1 deletion

File tree

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ const testHandler = (req, res) => {
6060
// Abort if user is blocked
6161
if (blockList.indexOf(req.params.user) !== -1) {
6262
ErrorHandler.log(`Request blocked for user ${req.params.user}`)
63+
64+
const template = require(__dirname + '/templates/blocklist.status.js')
65+
const blockListTemplate = template(req)
6366

64-
return res.status(429).send()
67+
return res.status(blockListTemplate.statusCode).send(blockListTemplate.body)
6568
}
6669

6770
const speedtracker = new SpeedTracker({

templates/blocklist.status.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
const utils = require(__dirname + '/../lib/utils')
2+
3+
const blocklist = (req) => {
4+
const body = `
5+
<!DOCTYPE html>
6+
<html lang="en">
7+
<head>
8+
<meta charset="utf-8">
9+
<title>403 Forbidden!</title>
10+
<style>
11+
header {
12+
width: 100%;
13+
height: 100px;
14+
background-color: #CB4C3D;
15+
color: white;
16+
text-align: center;
17+
display: -webkit-box;
18+
display: -ms-flexbox;
19+
display: flex;
20+
-webkit-box-pack: center;
21+
-ms-flex-pack: center;
22+
justify-content: center;
23+
-webkit-box-align: center;
24+
-ms-flex-align: center;
25+
align-items: center;
26+
}
27+
28+
code {
29+
font-weight: bold;
30+
font-style: italic;
31+
background-color: #EFF0F1;
32+
}
33+
</style>
34+
</head>
35+
<body>
36+
<main>
37+
<header>
38+
<h1>ERROR 403 - Forbidden!</h1>
39+
</header>
40+
<section>
41+
<h2>The following error occurrred:</h2>
42+
<p>Requests for user <code>${req.params.user}</code> are blocked.</p>
43+
<hr>
44+
<p>If you believe this is an error or would like to dispute this block then contact: <a href="mailto:abuse@speedtracker.org">abuse@speedtracker.org</a></p>
45+
</section>
46+
</main>
47+
</body>
48+
</html>
49+
`
50+
51+
return {
52+
body,
53+
statusCode: 403
54+
}
55+
}
56+
57+
module.exports = blocklist

0 commit comments

Comments
 (0)