我正在尝试制作一个中间件来从路径中删除区域设置字符串(例如/de/about
- > /about
),而我正在使用express。我尝试了以下中间件:
app.use(function (req, res, next) {
var localeMatch = /^\/([a-z]{2}(?:\-[A-Z]{2})?)(\/.+)$/.exec(req.path);
if (localeMatch) {
req.locale = localeMatch[1];
req.path = localeMatch[2];
} else {
req.locale = 'en-GB';
}
next();
});
它不起作用,因为req.path
是只读的。我怎么能这样做?