1
我試圖製作一箇中間件來從路徑中刪除區域設置字符串(例如/de/about
- >),並且我使用express。我試過以下中間件:在expressjs中間件中修改req.path
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
是隻讀的。我怎樣才能做到這一點?