Launch Ghost in a subdirectory of my main Node.js application

I am trying to run Ghost in a subdirectory of my main Node.js project. It is currently hosted on azure websites.
Something like: http://randomurlforpost.azurewebsites.net/blog

I followed the instructions below: https://github.com/TryGhost/Ghost/wiki/Using-Ghost-as-an-NPM-module

With the new addition of using Ghost as an npm module, do I still need Nginx or Apache ?. At the moment, I have my main site running on localhost: 3000 and an instance of Ghost running on localhost: 2368.

I tried to make all kinds of modifications for the part of the code indicated in the instructions, but I did not succeed.

//app.js, is there a specific place to put this? var ghost = require('ghost'); ghost().then(function (ghostServer) { ghostServer.start(); }); //config.js development: { url: 'http://localhost:3000/blog', database: { client: 'sqlite3', connection: { filename: path.join(__dirname, '/content/data/ghostdev.db') }, debug: false }, server: { host: '127.0.0.1', port: '2368' }, paths: { contentPath: path.join(__dirname, '/content/'), } }, //index.js ghost().then(function (ghostServer) { parentApp.use(ghostServer.config.paths.subdir,ghostServer.rootApp); // Let ghost handle starting our server instance. ghostServer.start(parentApp); }).catch(function (err) { errors.logErrorAndExit(err, err.context, err.help); }); 

EDIT : I managed to route traffic using http-proxy, but it directs it to localhost: 2368 / blog (which doesn't exist) any ideas on how to prevent this?

 var httpProxy = require('http-proxy'); var blogProxy = httpProxy.createProxyServer(); var ghost = require('ghost'); var path = require('path'); // Route /blog* to Ghost router.get("/blog*", function(req, res, next){ blogProxy.ws(req, res, { target: 'http://localhost:2368' }); }); 
+6
source share
1 answer

I had the same problem, and I first tried using Apache ProxyPass to redirect /blog to port 2368 , but found other problems doing this.

Before proceeding with my suggestions, you must undo any changes made using httpproxy .

It seems to have worked for me - put the code that you have in index.js directly into your app.js file instead of what you already have. You will need to add the ghost error variable and rename parentApp to the name of your application, I will call it yourAppName to yourAppName it, but mine is just an app . So, inside app.js you can put:

 var yourAppName = express(); var ghost = require('ghost'); var ghosterrors = require('ghost/core/server/errors') ghost().then(function(ghostServer) { yourAppName.use(ghostServer.config.paths.subdir, ghostServer.rootApp); ghostServer.start(yourAppName); }).catch(function(err) { errors.logErrorAndExit(err, err.context, err.help); }); 

You probably already have the ghost and express variables declared in app.js, so you don't need to add these lines.

The blog should now be available at the address specified in config.js.

+2
source

Source: https://habr.com/ru/post/981428/


All Articles