Node.js 在expressjs中间件中修改req.path

Node.js 在expressjs中间件中修改req.path,node.js,express,routing,Node.js,Express,Routing,我正在尝试制作一个中间件来从路径中删除区域设置字符串(例如,/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];

我正在尝试制作一个中间件来从路径中删除区域设置字符串(例如,
/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
是只读的,所以它不起作用。我该怎么做?

看看Express。您可以在每个“子应用程序”上都有一个处理功能,但您的所有地区都可以使用相同的路径