add basic rate limiting

This commit is contained in:
Ondrej Synacek 2019-10-21 20:44:34 +02:00
parent e4200690d9
commit 6a1ef614ad
4 changed files with 8 additions and 26 deletions

View File

@ -2,6 +2,7 @@ const express = require('express')
const bodyParser = require('body-parser')
const path = require('path')
const favicon = require('serve-favicon')
const rateLimit = require('express-rate-limit')
const crawl = require('./crawler')
const parseHTML = require('./parser')
@ -30,18 +31,13 @@ app.get('/error', (req, res) => {
.render('error', { error })
})
app.get('/download', (req, res) => {
res
.status(200)
.render('download')
})
// NOTE: Capture all unkown URLs
app.get('*', (req, res) => {
res.status(400).render('404')
})
app.use('/download', checkFBURL)
app.use('/download', rateLimit())
app.post('/download', async (req, res) => {
const { url } = req.body

View File

@ -1,20 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Facebook Events to iCal Converter | download</title>
</head>
<body>
<h2>Your ICS file is ready</h2>
<p>
The <code>ics</code> file was created successfully from url
<a href="<%= url %>"><%= url %></a>.
</p>
<p>
Your download will start automatically.
</p>
<a href="/">Go back</a>
</body>
</html>

5
package-lock.json generated
View File

@ -860,6 +860,11 @@
"vary": "~1.1.2"
}
},
"express-rate-limit": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-5.0.0.tgz",
"integrity": "sha512-dhT57wqxfqmkOi4HM7NuT4Gd7gbUgSK2ocG27Y6lwm8lbOAw9XQfeANawGq8wLDtlGPO1ZgDj0HmKsykTxfFAg=="
},
"extend": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz",

View File

@ -24,6 +24,7 @@
"dayjs": "^1.8.16",
"ejs": "^2.7.1",
"express": "^4.17.1",
"express-rate-limit": "^5.0.0",
"ics": "^2.18.0",
"request": "^2.88.0",
"serve-favicon": "^2.5.0"