@ladjs/web 17.0.10 → 18.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +42 -38
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -254,16 +254,6 @@ class Web {
254
254
  // basic auth
255
255
  if (this.config.auth) app.use(auth(this.config.auth));
256
256
 
257
- // rate limiting
258
- if (this.config.rateLimit)
259
- app.use(
260
- ratelimit({
261
- ...this.config.rateLimit,
262
- db: this.client,
263
- logger: this.logger
264
- })
265
- );
266
-
267
257
  // remove trailing slashes
268
258
  app.use(removeTrailingSlashes());
269
259
 
@@ -339,39 +329,16 @@ class Web {
339
329
  const stateHelper = new StateHelper(this.config.views.locals);
340
330
  app.use(stateHelper.middleware);
341
331
 
342
- // add specific locals
343
- app.use((ctx, next) => {
344
- // passport-related helpers (e.g. for rendering log in with X buttons)
345
- ctx.state.passport = ctx.passport ? {} : false;
346
- if (
347
- ctx.passport &&
348
- ctx.passport.config &&
349
- ctx.passport.config.providers
350
- ) {
351
- for (const key of Object.keys(ctx.passport.config.providers)) {
352
- ctx.state.passport[key] = boolean(ctx.passport.config.providers[key]);
353
- }
354
- }
355
-
356
- // add limited `ctx` object to the state for views
357
- ctx.state.ctx = {};
358
- ctx.state.ctx.get = ctx.get.bind(ctx);
359
- ctx.state.ctx.locale = ctx.locale;
360
- ctx.state.ctx.path = ctx.path;
361
- ctx.state.ctx.pathWithoutLocale = ctx.pathWithoutLocale;
362
- ctx.state.ctx.query = ctx.query;
363
- ctx.state.ctx.sessionId = ctx.sessionId;
364
- ctx.state.ctx.url = ctx.url;
365
-
366
- return next();
367
- });
368
-
369
332
  // session store
370
333
  app.keys = this.config.sessionKeys;
371
334
  app.use(
372
335
  session({
373
336
  ...this.config.session,
374
- store: redisStore({ client: this.client }),
337
+ ...(this.client
338
+ ? {
339
+ store: redisStore({ client: this.client })
340
+ }
341
+ : {}),
375
342
  key: this.config.cookiesKey,
376
343
  cookie: this.config.cookies,
377
344
  genSid: this.config.genSid
@@ -423,6 +390,43 @@ class Web {
423
390
  app.use(this.passport.session());
424
391
  }
425
392
 
393
+ // add specific locals
394
+ app.use((ctx, next) => {
395
+ // passport-related helpers (e.g. for rendering log in with X buttons)
396
+ ctx.state.passport = ctx.passport ? {} : false;
397
+ if (
398
+ ctx.passport &&
399
+ ctx.passport.config &&
400
+ ctx.passport.config.providers
401
+ ) {
402
+ for (const key of Object.keys(ctx.passport.config.providers)) {
403
+ ctx.state.passport[key] = boolean(ctx.passport.config.providers[key]);
404
+ }
405
+ }
406
+
407
+ // add limited `ctx` object to the state for views
408
+ ctx.state.ctx = {};
409
+ ctx.state.ctx.get = ctx.get.bind(ctx);
410
+ ctx.state.ctx.locale = ctx.locale;
411
+ ctx.state.ctx.path = ctx.path;
412
+ ctx.state.ctx.pathWithoutLocale = ctx.pathWithoutLocale;
413
+ ctx.state.ctx.query = ctx.query;
414
+ ctx.state.ctx.sessionId = ctx.sessionId;
415
+ ctx.state.ctx.url = ctx.url;
416
+
417
+ return next();
418
+ });
419
+
420
+ // rate limiting
421
+ if (this.client && this.config.rateLimit)
422
+ app.use(
423
+ ratelimit({
424
+ ...this.config.rateLimit,
425
+ db: this.client,
426
+ logger: this.logger
427
+ })
428
+ );
429
+
426
430
  // store the user's last ip address in the background
427
431
  if (this.config.storeIPAddress) {
428
432
  const storeIPAddress = new StoreIPAddress({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ladjs/web",
3
3
  "description": "Web server for Lad",
4
- "version": "17.0.10",
4
+ "version": "18.0.2",
5
5
  "author": "Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com/)",
6
6
  "bugs": {
7
7
  "url": "https://github.com/ladjs/web/issues",
@@ -12,7 +12,7 @@
12
12
  ],
13
13
  "dependencies": {
14
14
  "@hapi/boom": "^10.0.0",
15
- "@koa/router": "^11.0.0",
15
+ "@koa/router": "^11.0.1",
16
16
  "@ladjs/i18n": "^8.0.1",
17
17
  "@ladjs/koa-better-static": "^2.0.1",
18
18
  "@ladjs/koa-cache-responses": "^0.0.3",
@@ -31,7 +31,7 @@
31
31
  "koa": "^2.13.4",
32
32
  "koa-404-handler": "^0.1.0",
33
33
  "koa-basic-auth": "^4.0.0",
34
- "koa-better-error-handler": "^10.0.6",
34
+ "koa-better-error-handler": "^10.0.7",
35
35
  "koa-better-flash": "^0.0.4",
36
36
  "koa-better-timeout": "^0.0.6",
37
37
  "koa-bodyparser": "^4.3.0",