使用Angular2的http路由而不是vhost?

时间:2016-08-05 16:02:44

标签: node.js typescript angular angular2-http

我有一个基于nodeJS的网络应用程序,我希望有一个博客子域名。这是一个静态(基于Hexo)的博客。所以我目前正在http://localhost:4000/上的博客和http://localhost:4200/上的角色应用程序服务,项目目录如下:

project
  |--------Hexo Blog
  |            |------all Blog files
  |
  |--------Angular App
               |------all ng2 files

我想一种方法是使用Express app.js和vhost将博客子域路由到不同的端口,有点像这样:

app.use(function (req, res, next) {
    if (req.headers.host) {
        if (typeof req.headers.host === 'string' && req.headers.host.match(/blog\.myDomain\.com/)) { // a simple url match.
            proxy.web(req, res, { target: 'http://0.0.0.0:4000/' }); // hexo is running on this host and you can change it.
        } else {
            next(); // pass the request to other app.
        }
    }
});

但是,如果不需要,我宁愿不将express和vhost添加为依赖项。这是我可以用Angular做的事吗?

0 个答案:

没有答案