diff --git a/lib/index.js b/lib/index.js index c0bb58b..4d54e83 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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 diff --git a/lib/views/download.ejs b/lib/views/download.ejs deleted file mode 100644 index 12a1567..0000000 --- a/lib/views/download.ejs +++ /dev/null @@ -1,20 +0,0 @@ - - - - - Facebook Events to iCal Converter | download - - - -

Your ICS file is ready

- -

- The ics file was created successfully from url - <%= url %>. -

-

- Your download will start automatically. -

- Go back - - diff --git a/package-lock.json b/package-lock.json index da5436d..21fe02c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 524e933..a737340 100644 --- a/package.json +++ b/package.json @@ -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"