Skip to content

Commit

Permalink
Allow rate limiting to be disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-blunden committed Oct 2, 2020
1 parent b360096 commit cfddc83
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ PORT="3000"
TRANSLATION_SUGGESTION="Secrets must not be stored in git repositories"
YODA_TRANSLATE_API_ENDPOINT="https://api.funtranslations.com/translate/yoda.json"
YODA_TRANSLATE_API_KEY=""
RATE_LIMITING_ENABLED="false"
1 change: 1 addition & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const config = Object.freeze({
TRANSLATION_SUGGESTION: process.env.TRANSLATION_SUGGESTION,
YODA_TRANSLATE_API_ENDPOINT: process.env.YODA_TRANSLATE_API_ENDPOINT,
YODA_TRANSLATE_API_KEY: process.env.YODA_TRANSLATE_API_KEY,
RATE_LIMITING_ENABLED: process.env.RATE_LIMITING_ENABLED === 'true' ? true : false,
})

export default config
6 changes: 5 additions & 1 deletion src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ const PREDEFINED_TRANSLATIONS = {

const app = express()
const router = express.Router()

if (config.RATE_LIMITING_ENABLED) {
console.log(colors.green('[info]: rate limiting enabled'))
}
const translationLimiter = rateLimit({
windowMs: 60 * 60 * 1000,
max: 60,
max: config.RATE_LIMITING_ENABLED ? 60 : 0,
handler: (req, res) => {
res.json({
text: req.body.text,
Expand Down

0 comments on commit cfddc83

Please sign in to comment.