Node.js How to Rewrite URL in server.js

1.6k views Asked by At

I am using node.js with easyrtc and need to rewrite url or remove any url after slash

please find my 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);

where can I add the script to rewrite url ?

1

There are 1 answers

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

You can still access original URL http://expressjs.com/api.html#req.originalUrl