0

I wanna override url before app.router parsed.

Insert path like http://example.com/#{uid}/#{trueURI}

should to be http://example.com/#{trueURI}

I use following code:

app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(cookieParser);
app.use(express.session());
app.use(function (req, res, next) {
    paths = req.path.split('/');
    paths.shift();
    req.session.uid = paths[0];
    paths.shift();
    req.path = "/" + paths.join('/');  // Cannot set this
    next();
});
app.use(express.static(path.join(__dirname, 'public')));
app.use(app.router);
app.use(require('stylus').middleware(__dirname + '/public'));

The req.path only have getter, but setter is unused.

So, how could I replace url every request in express/connect framework?

Thanks for your read.

4

1 回答 1

4

这似乎有效:

app.use(function(req, res, next) {
  req.url = req.url.replace(/^\/.*?\//, '/');
  next();
});
于 2013-11-05T11:42:41.003 回答