Node.js如何在server.js中重写URL

时间:2014-01-22 12:06:36

标签: node.js express easyrtc

我正在使用带有easyrtc的node.js,需要重写url或删除斜杠后的任何url

请找到我的server.js

var http    = require("http");         
var express = require("express");      
var io      = require("socket.io");    
var easyrtc = require("easyrtc");      
var httpApp = express();
httpApp.configure(function() {
httpApp.use(express.static(__dirname + "/static/"));
});
var webServer = http.createServer(httpApp).listen(9099);
var socketServer = io.listen(webServer, {"log level":5});
var rtc = easyrtc.listen(httpApp, socketServer);

我可以在哪里添加脚本来重写网址?

1 个答案:

答案 0 :(得分:1)

httpApp.configure(function() {
  httpApp.use(function(req, res, next){
    if(req.url === '/myOldRoute'){
      req.url = '/myNewRoute'
    }
    next();
  });
  httpApp.use(express.static(__dirname + "/static/"));
});

您仍然可以访问原始网址http://expressjs.com/api.html#req.originalUrl