UNPKG

884 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.trailingSlashRedirect = void 0;
4var debug_ = require("debug");
5var debug = debug_("r2:streamer#http/server-trailing-slash-redirect");
6function 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}
23exports.trailingSlashRedirect = trailingSlashRedirect;
24//# sourceMappingURL=server-trailing-slash-redirect.js.map
\No newline at end of file