@ladjs/web 21.0.6 → 21.0.8

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 +14 -2
  2. package/package.json +2 -3
package/index.js CHANGED
@@ -37,7 +37,6 @@ const methodOverride = require('koa-methodoverride');
37
37
  const ms = require('ms');
38
38
  const ratelimit = require('@ladjs/koa-simple-ratelimit');
39
39
  const redisStore = require('koa-redis');
40
- const removeTrailingSlashes = require('koa-no-trailing-slash');
41
40
  const requestId = require('express-request-id');
42
41
  const requestReceived = require('request-received');
43
42
  const responseTime = require('response-time');
@@ -47,6 +46,19 @@ const sharedConfig = require('@ladjs/shared-config');
47
46
  const views = require('@ladjs/koa-views');
48
47
  const { boolean } = require('boolean');
49
48
 
49
+ // https://gist.github.com/titanism/241fc0c5f1c1a0b7cae3d97580e435fb
50
+ function removeTrailingSlashes(ctx, next) {
51
+ const { path, search } = ctx.request;
52
+ if (path !== '/' && !path.startsWith('//') && path.slice(-1) === '/') {
53
+ const redirectUrl = path.slice(0, -1) + search;
54
+ ctx.response.status = 301;
55
+ ctx.redirect(redirectUrl);
56
+ return;
57
+ }
58
+
59
+ return next();
60
+ }
61
+
50
62
  const defaultSrc = isSANB(process.env.WEB_HOST)
51
63
  ? [
52
64
  "'self'",
@@ -241,7 +253,7 @@ class Web {
241
253
  if (this.config.auth) app.use(auth(this.config.auth));
242
254
 
243
255
  // remove trailing slashes
244
- app.use(removeTrailingSlashes());
256
+ app.use(removeTrailingSlashes);
245
257
 
246
258
  // security
247
259
  // (needs to come before i18n so HSTS header gets added)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ladjs/web",
3
3
  "description": "Web server for Lad",
4
- "version": "21.0.6",
4
+ "version": "21.0.8",
5
5
  "author": "Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com/)",
6
6
  "bugs": {
7
7
  "url": "https://github.com/ladjs/web/issues",
@@ -11,7 +11,7 @@
11
11
  "Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com/)"
12
12
  ],
13
13
  "dependencies": {
14
- "@koa/router": "^12.0.0",
14
+ "@koa/router": "^12.0.1",
15
15
  "@ladjs/i18n": "^8.0.3",
16
16
  "@ladjs/koa-better-static": "^2.0.1",
17
17
  "@ladjs/koa-cache-responses": "^0.0.3",
@@ -45,7 +45,6 @@
45
45
  "koa-json": "^2.0.2",
46
46
  "koa-meta": "^4.0.1",
47
47
  "koa-methodoverride": "^2.0.0",
48
- "koa-no-trailing-slash": "^2.1.0",
49
48
  "koa-redirect-loop": "^3.0.2",
50
49
  "koa-redis": "^4.0.1",
51
50
  "lodash": "^4.17.21",