1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.trailingSlashRedirect = void 0;
|
4 | var debug_ = require("debug");
|
5 | var debug = debug_("r2:streamer#http/server-trailing-slash-redirect");
|
6 | function trailingSlashRedirect(req, res, next) {
|
7 | var i = req.originalUrl.indexOf("?");
|
8 | var pathWithoutQuery = req.originalUrl;
|
9 | if (i >= 0) {
|
10 | pathWithoutQuery = pathWithoutQuery.substr(0, i);
|
11 | }
|
12 | if (pathWithoutQuery.substr(-1) === "/"
|
13 | || pathWithoutQuery.indexOf(".") >= 0) {
|
14 | return next();
|
15 | }
|
16 | var redirect = pathWithoutQuery + "/";
|
17 | if (i >= 0) {
|
18 | redirect += req.originalUrl.substr(i);
|
19 | }
|
20 | debug("REDIRECT: " + req.originalUrl + " ==> " + redirect);
|
21 | res.redirect(301, redirect);
|
22 | }
|
23 | exports.trailingSlashRedirect = trailingSlashRedirect;
|
24 |
|
\ | No newline at end of file |