【发布时间】:2016-06-21 01:50:42
【问题描述】:
我正在尝试制作一个中间件来从路径中删除语言环境字符串(例如/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 是只读的。我该怎么做?
【问题讨论】: