1

我正在将 node.js 与 easyrtc 一起使用,需要重写 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);

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

4

1 回答 1

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

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

于 2014-01-22T12:11:36.607 回答