UNPKG

2.24 kBSource Map (JSON)View Raw
1{"version":3,"file":"server-trailing-slash-redirect.js","sourceRoot":"","sources":["../../../../src/http/server-trailing-slash-redirect.ts"],"names":[],"mappings":";;;AAOA,8BAAgC;AAGhC,IAAM,KAAK,GAAG,MAAM,CAAC,iDAAiD,CAAC,CAAC;AAGxE,SAAgB,qBAAqB,CAAC,GAAoB,EAAE,GAAqB,EAAE,IAA0B;IAEzG,IAAM,CAAC,GAAG,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAEvC,IAAI,gBAAgB,GAAG,GAAG,CAAC,WAAW,CAAC;IACvC,IAAI,CAAC,IAAI,CAAC,EAAE;QACR,gBAAgB,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;KACpD;IACD,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG;WAChC,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;QACvC,OAAO,IAAI,EAAE,CAAC;KACjB;IAED,IAAI,QAAQ,GAAG,gBAAgB,GAAG,GAAG,CAAC;IACtC,IAAI,CAAC,IAAI,CAAC,EAAE;QACR,QAAQ,IAAI,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;KACzC;IAKD,KAAK,CAAC,eAAa,GAAG,CAAC,WAAW,aAAQ,QAAU,CAAC,CAAC;IACtD,GAAG,CAAC,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;AAChC,CAAC;AAvBD,sDAuBC","sourcesContent":["// ==LICENSE-BEGIN==\n// Copyright 2017 European Digital Reading Lab. All rights reserved.\n// Licensed to the Readium Foundation under one or more contributor license agreements.\n// Use of this source code is governed by a BSD-style license\n// that can be found in the LICENSE file exposed on Github (readium) in the project repository.\n// ==LICENSE-END==\n\nimport * as debug_ from \"debug\";\nimport * as express from \"express\";\n\nconst debug = debug_(\"r2:streamer#http/server-trailing-slash-redirect\");\n\n// https://github.com/avinoamr/connect-slashes\nexport function trailingSlashRedirect(req: express.Request, res: express.Response, next: express.NextFunction) {\n\n const i = req.originalUrl.indexOf(\"?\");\n\n let pathWithoutQuery = req.originalUrl;\n if (i >= 0) {\n pathWithoutQuery = pathWithoutQuery.substr(0, i);\n }\n if (pathWithoutQuery.substr(-1) === \"/\"\n || pathWithoutQuery.indexOf(\".\") >= 0) {\n return next();\n }\n\n let redirect = pathWithoutQuery + \"/\";\n if (i >= 0) {\n redirect += req.originalUrl.substr(i);\n }\n\n // Note that the HTTP 301 redirect does not contain CORS headers\n // server.setResponseCORS(res);\n\n debug(`REDIRECT: ${req.originalUrl} ==> ${redirect}`);\n res.redirect(301, redirect);\n}\n"]}
\No newline at end of file