在快速应用上本地使用子域

我有快递节点应用程序运行。 我想设置两种不同的帐户types(一个用于买方,一个用于卖方),并且可以通过不同的子域(例如buyers.example.com和sellers.example.com)访问它们。 我不知道如何在本地设置。 我知道我可以编辑我的机器上的主机文件,使*.localhostparsing为127.0.0.1 ,但是这并不能解决我的问题。 在这种情况下, buyers.localhost/loginbuyers.localhost/login sellers.localhost/login将路由到相同的地方。 这是一个常见的问题,如果是这样,处理这个问题的标准方法是什么? 我有什么select来分开处理两种账户types的逻辑?

首先添加这个:

 app.get('*', function(req, res, next){ if (req.headers.host == 'buyers.localhost:5000') { //Port is important if the url has it req.url = '/buyers' + req.url; } else if(req.headers.host == 'sellers.localhost:5000') { req.url = '/sellers' + req.url; } next(); }); 

接着:

 app.get('/login', function(){ //Default case, no subdomain }) app.get('/buyers/login', function(){ //Buyers subdomain }) app.get('/sellers/login', function(){ //Sellers subdomain }) 

了解到这里: https : //groups.google.com/forum/#!topic/ express-js/ sEu66n8Oju0