@ladjs/api 14.1.6 → 14.1.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.
- package/index.js +14 -2
- package/package.json +2 -3
package/index.js
CHANGED
|
@@ -21,13 +21,25 @@ const koa404Handler = require('koa-404-handler');
|
|
|
21
21
|
const koaConnect = require('koa-connect');
|
|
22
22
|
const multimatch = require('multimatch');
|
|
23
23
|
const ratelimit = require('@ladjs/koa-simple-ratelimit');
|
|
24
|
-
const removeTrailingSlashes = require('koa-no-trailing-slash');
|
|
25
24
|
const requestId = require('express-request-id');
|
|
26
25
|
const requestReceived = require('request-received');
|
|
27
26
|
const responseTime = require('response-time');
|
|
28
27
|
const sharedConfig = require('@ladjs/shared-config');
|
|
29
28
|
const { boolean } = require('boolean');
|
|
30
29
|
|
|
30
|
+
// https://gist.github.com/titanism/241fc0c5f1c1a0b7cae3d97580e435fb
|
|
31
|
+
function removeTrailingSlashes(ctx, next) {
|
|
32
|
+
const { path, search } = ctx.request;
|
|
33
|
+
if (path !== '/' && !path.startsWith('//') && path.slice(-1) === '/') {
|
|
34
|
+
const redirectUrl = path.slice(0, -1) + search;
|
|
35
|
+
ctx.response.status = 301;
|
|
36
|
+
ctx.redirect(redirectUrl);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return next();
|
|
41
|
+
}
|
|
42
|
+
|
|
31
43
|
class API {
|
|
32
44
|
// eslint-disable-next-line complexity
|
|
33
45
|
constructor(config, Users) {
|
|
@@ -108,7 +120,7 @@ class API {
|
|
|
108
120
|
if (this.config.auth) app.use(auth(this.config.auth));
|
|
109
121
|
|
|
110
122
|
// Remove trailing slashes
|
|
111
|
-
app.use(removeTrailingSlashes
|
|
123
|
+
app.use(removeTrailingSlashes);
|
|
112
124
|
|
|
113
125
|
// I18n
|
|
114
126
|
if (this.config.i18n) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ladjs/api",
|
|
3
3
|
"description": "API server for Lad",
|
|
4
|
-
"version": "14.1.
|
|
4
|
+
"version": "14.1.8",
|
|
5
5
|
"author": "Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com/)",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/ladjs/api/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.
|
|
14
|
+
"@koa/router": "^12.0.1",
|
|
15
15
|
"@ladjs/i18n": "^8.0.3",
|
|
16
16
|
"@ladjs/koa-simple-ratelimit": "^4.1.1",
|
|
17
17
|
"@ladjs/passport": "^5.0.3",
|
|
@@ -32,7 +32,6 @@
|
|
|
32
32
|
"koa-connect": "^2.1.0",
|
|
33
33
|
"koa-etag": "^4.0.0",
|
|
34
34
|
"koa-json": "^2.0.2",
|
|
35
|
-
"koa-no-trailing-slash": "^2.1.0",
|
|
36
35
|
"lodash": "^4.17.21",
|
|
37
36
|
"multimatch": "5",
|
|
38
37
|
"request-received": "^0.0.3",
|