diff options
Diffstat (limited to 'app/Middleware')
-rw-r--r-- | app/Middleware/HandleDoubleSlash.js | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/app/Middleware/HandleDoubleSlash.js b/app/Middleware/HandleDoubleSlash.js new file mode 100644 index 0000000..94f4fe8 --- /dev/null +++ b/app/Middleware/HandleDoubleSlash.js | |||
@@ -0,0 +1,26 @@ | |||
1 | 'use strict' | ||
2 | /** @typedef {import('@adonisjs/framework/src/Request')} Request */ | ||
3 | /** @typedef {import('@adonisjs/framework/src/Response')} Response */ | ||
4 | /** @typedef {import('@adonisjs/framework/src/View')} View */ | ||
5 | |||
6 | class HandleDoubleSlash { | ||
7 | /** | ||
8 | * @param {object} ctx | ||
9 | * @param {Request} ctx.request | ||
10 | * @param {Function} next | ||
11 | */ | ||
12 | async handle ({ request, response }, next) { | ||
13 | console.log(request.url()); | ||
14 | |||
15 | // Redirect requests that contain duplicate slashes to the right path | ||
16 | if (request.url().includes('//')) { | ||
17 | return response.redirect( | ||
18 | request.url().replace(/\/{2,}/g, '/'), | ||
19 | ); | ||
20 | } | ||
21 | |||
22 | await next(); | ||
23 | } | ||
24 | } | ||
25 | |||
26 | module.exports = HandleDoubleSlash | ||