可以从快递中提交另一个快递申请吗?

时间:2015-07-08 19:35:25

标签: node.js express ghost

基本上发生的事情是我们有一个运行快速的应用服务器并路由到一堆SPA。这很棒,但后来我们想要一个运行自己的node / express脚本(ghost)的应用程序。我无法弄清楚如何设置路线/幽灵去./webapps/ghost/index.js

这是不可能的吗?

1 个答案:

答案 0 :(得分:3)

您需要将传入的请求重定向到ghost express实例。我已经在我的个人网站上添加了/ blog路由到我的主要快递实例并将任何请求转发给ghost expresss实例。请在此处查看:https://github.com/evanshortiss/evanshortiss.com/blob/master/server.js

基本要点是你要做到以下几点:

app.use('/blog', function(req, res, next) {
  // Forward this request on...
  return next();
}, ghostServer.rootApp); //...but we forward it to a different express instance

如果您作为单独的进程运行,那么您可以使用Apache或nginx来重定向请求。如果您绝对必须使用快速应用程序转发请求,请尝试使用node-http-proxy模块。

如果您需要从express代理,可以使用Nodejitsu的http-proxy模块执行此操作:

var proxy = require('http-proxy').createProxyServer({});

app.use('/blog', function (req, res) {
  // You may need to edit req.url (or similar) to strip the /blog part of the url or ghost might not recognise it
  proxy.web(req, res, {
    target: 'http://127.0.0.1:'+GHOST_PORT
  });
});
相关问题