具有Restify和nodejs的多个子域
我正在使用Restify开发nodejs应用程序。 应用程序必须为应用程序提供一个API,一个基于angular度使用API的静态公共站点,另一个静态但私有的angular度站点,pipe理UI也会使用该API。
我已经设法为公共静态网站和API设置路由。 pipe理员给我头痛。 我需要在不同的子域中暴露pipe理员,例如: admin.mysite.com
,而api和公共站点则在www.mysite.com
( www.mysite.com
的api)上提供。
这是我迄今为止configuration它:
// restify route configuration for the public HTML site server.get(/^\/(?!api)/, restify.serveStatic({ directory: './client/', default: 'index.html' })); // restify route configuration for the API, using directory structure for route setup. routes(function(routes){ console.log(routes); routes.forEach(function(route){ server[route.method](route.route, route.handler); }); });
我怎样才能configurationrestify服务,通过serveStatic
,pipe理的HTML用户界面在不同的子域在同一个nodejs服务器上?
尝试这样的事情:
app.get('/', function(req, res) { var hostname = req.headers.host.split(":")[0]; if(hostname == "sub1.domain.com") res.send("this is sub1 response!"); else if(hostname == "sub2.domain.com") res.send("this is sub2 response!"); });
参考:
http://code4node.com/snippet/http-proxy-with-custom-routing
从: