node.js - Is it possible to render another express application from express? -
basically happened have app server running express , routes bunch of spas. great wanted have app runs own node/express script (ghost). can't figure out how set route /ghost go ./webapps/ghost/index.js
is not possible?
you need redirect incoming requests ghost express instance. have done in personal site adding /blog route primary express instance , forwarding request ghost expresss instance. check out here: https://github.com/evanshortiss/evanshortiss.com/blob/master/server.js
the basic gist following:
app.use('/blog', function(req, res, next) { // forward request on... return next(); }, ghostserver.rootapp); //...but forward different express instance
if you're running both separate processes use apache or nginx redirect requests. if absolutely must use express application forward requests try node-http-proxy module.
if need proxy express using http-proxy module nodejitsu:
var proxy = require('http-proxy').createproxyserver({}); app.use('/blog', function (req, res) { // may need edit req.url (or similar) strip /blog part of url or ghost might not recognise proxy.web(req, res, { target: 'http://127.0.0.1:'+ghost_port }); });
Comments
Post a Comment