@ladjs/web
Advanced tools
Comparing version 0.2.7 to 0.2.8
48
index.js
@@ -18,3 +18,3 @@ const http = require('http'); | ||
const responseTime = require('koa-response-time'); | ||
const rateLimit = require('koa-simple-ratelimit'); | ||
const rateLimiter = require('koa-simple-ratelimit'); | ||
const views = require('koa-views'); | ||
@@ -45,9 +45,19 @@ const koaLogger = require('koa-logger'); | ||
let max = process.env.RATELIMIT_MAX | ||
? parseInt(process.env.RATELIMIT_MAX, 10) | ||
: 100; | ||
const env = process.env.NODE_ENV || 'development'; | ||
if (!process.env.RATELIMIT_MAX && process.env.NODE_ENV === 'development') | ||
max = Number.MAX_VALUE; | ||
let rateLimit = { | ||
duration: process.env.RATELIMIT_DURATION | ||
? parseInt(process.env.RATELIMIT_DURATION, 10) | ||
: 60000, | ||
max: process.env.RATELIMIT_MAX | ||
? parseInt(process.env.RATELIMIT_MAX, 10) | ||
: 100, | ||
id: ctx => ctx.ip, | ||
prefix: process.env.RATELIMIT_PREFIX | ||
? process.env.RATELIMIT_PREFIX | ||
: `limit_${env.toLowerCase()}` | ||
}; | ||
if (env === 'development') rateLimit = false; | ||
class Server { | ||
@@ -76,12 +86,3 @@ // eslint-disable-next-line complexity | ||
passport: false, | ||
rateLimit: { | ||
duration: process.env.RATELIMIT_DURATION | ||
? parseInt(process.env.RATELIMIT_DURATION, 10) | ||
: 60000, | ||
max, | ||
id: ctx => ctx.ip, | ||
prefix: process.env.RATELIMIT_PREFIX | ||
? process.env.RATELIMIT_PREFIX | ||
: `limit_${process.env.NODE_ENV.toLowerCase()}` | ||
}, | ||
rateLimit, | ||
// <https://github.com/koajs/cors#corsoptions> | ||
@@ -221,8 +222,9 @@ cors: {}, | ||
// rate limiting | ||
app.use( | ||
rateLimit({ | ||
...this.config.rateLimit, | ||
db: redisClient | ||
}) | ||
); | ||
if (this.config.rateLimit) | ||
app.use( | ||
rateLimiter({ | ||
...this.config.rateLimit, | ||
db: redisClient | ||
}) | ||
); | ||
@@ -236,3 +238,3 @@ // conditional-get | ||
// cors | ||
app.use(cors(this.config.cors)); | ||
if (this.config.cors) app.use(cors(this.config.cors)); | ||
@@ -239,0 +241,0 @@ // TODO: add `cors-gate` |
{ | ||
"name": "@ladjs/web", | ||
"description": "Web server for Lad", | ||
"version": "0.2.7", | ||
"version": "0.2.8", | ||
"author": "Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com/)", | ||
@@ -18,7 +18,7 @@ "bugs": { | ||
"@ladjs/store-ip-address": "^0.0.5", | ||
"auto-bind": "^1.2.0", | ||
"auto-bind": "^1.2.1", | ||
"boolean": "^0.1.3", | ||
"boom": "5.2.0", | ||
"cabin": "^1.0.0", | ||
"common-tags": "^1.7.2", | ||
"cabin": "^1.0.2", | ||
"common-tags": "^1.8.0", | ||
"ip": "^1.1.5", | ||
@@ -61,10 +61,10 @@ "kcors": "^2.2.1", | ||
"codecov": "^3.0.2", | ||
"cross-env": "^5.1.5", | ||
"eslint": "^4.19.1", | ||
"cross-env": "^5.2.0", | ||
"eslint": "^5.0.0", | ||
"eslint-config-prettier": "^2.9.0", | ||
"eslint-plugin-prettier": "^2.6.0", | ||
"eslint-plugin-prettier": "^2.6.1", | ||
"husky": "^0.14.3", | ||
"lint-staged": "^7.1.2", | ||
"nyc": "^11.8.0", | ||
"prettier": "^1.12.1", | ||
"lint-staged": "^7.2.0", | ||
"nyc": "^12.0.2", | ||
"prettier": "^1.13.5", | ||
"remark-cli": "^5.0.0", | ||
@@ -99,7 +99,12 @@ "remark-preset-github": "^0.0.8", | ||
], | ||
"*.md": ["remark . -qfo", "git add"] | ||
"*.md": [ | ||
"remark . -qfo", | ||
"git add" | ||
] | ||
}, | ||
"main": "index.js", | ||
"remarkConfig": { | ||
"plugins": ["preset-github"] | ||
"plugins": [ | ||
"preset-github" | ||
] | ||
}, | ||
@@ -119,3 +124,5 @@ "repository": { | ||
"extends": "prettier", | ||
"plugins": ["prettier"], | ||
"plugins": [ | ||
"prettier" | ||
], | ||
"parserOptions": { | ||
@@ -122,0 +129,0 @@ "sourceType": "script" |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
330
30
282066
Updatedauto-bind@^1.2.1
Updatedcabin@^1.0.2
Updatedcommon-tags@^1.8.0