UNPKG

express-lowercase-paths-with-status-code

Version:

An Express middleware module that will redirect user HTTP requests that contain uppercase letters, to the same URL converted to lowercase, without modifying query parameters.

15 lines (13 loc) 421 B
var url = require("url") module.exports = function lowercasePaths(opts) { var _opts = opts || {} return function _lowercasePaths(req, res, next) { if (req.path.toLowerCase() !== req.path) { var parsedUrl = url.parse(req.originalUrl) parsedUrl.pathname = parsedUrl.pathname.toLowerCase() res.redirect(_opts.redirectStatusCode || 302, url.format(parsedUrl)) } else { next() } } }