2016-06-30 31 views
0

我希望能夠做這樣的事在快遞:如何將移動和桌面請求發送到不同的路由器?

var mobile = express.Router(), 
    desktop = express.Router(); 

mobile.get('/', function (req, res) { 
    // some routing for mobile devices 
}); 

desktop.get('/', function (req, res) { 
    // some routing for desktop devices 
}); 

app.use(function (req, res, next) { 
    var device = new MobileDetect(req.headers['user-agent']); 

    if (device.mobile()) 
     // send request to `mobile` router 
    else 
     // send request to `desktop` router 
}); 

讓我的遊戲的移動和桌面部分是完全不同的。 但是我找不到「將請求發送到路由器」的方法,有沒有辦法做到這一點?

感謝

+0

,那豈不是更好有一些中間件來檢測移動和重定向?例如http://therockncoder.blogspot.co.il/2013/11/mobile-device-detection-and-redirection.html。 –

+0

那麼這意味着移動部分在每個URL中都有一個/移動前綴,但爲什麼不 –

回答

1

你只需要調用這些路由器所期待中間件的參數:

if (device.mobile()) { 
    mobile(req, res, next) 
} else { 
    desktop(req, res, next) 
} 
相關問題