Run Ghost blog as subfolder of website running on node http-server
Asked Answered
S

3

9

First, forgive my lack of understanding of Joyent's smartmachine instance. I am running a free dev tier smartmachine instance of NodeJS for this scenario.

I am running a website at [path]/server/public/ on the filesystem via http-server and I want to simultaneously run a Ghost blog at [path]/server/public/blog/, both on port 80.

Is this possible? How would I accomplish it?

Sabrasabre answered 16/12, 2014 at 20:25 Comment(0)
E
8

Setting up a thin wrapper using express can be a good solution (as Paul recommends), but can be a mess if you end with a big application with a lot of "diferennt services".

Instead ill go for a proxy (NGINX for example) on top of all my services.

With this solution, if a service fails, the rest no since they are decoupled.

You can listen on port 80 and proxy internally to each service:port.

Something like:

0.0.0.0:80 ---> Proxy
                  └──path: /     ─── localhost:3000  (Main Web)
                  └──path: /blog ─── localhost:4000 (Ghost)
                  ...
Ejection answered 18/1, 2015 at 18:1 Comment(0)
W
3

If your other website is an express based site, the easiest thing would probably be to include your ghost app in the same source tree (in a subfolder perhaps). Express apps can be mounted as middleware to other express apps, so you could then add a route to your main site like:

var ghost = require('./path/to/ghost');
app.use('/blog', ghost);
Wallen answered 16/12, 2014 at 20:33 Comment(5)
Express is something I can look into, but it seems more complex than http-server. Can you suggest a solution to my question as-is?Sabrasabre
How would I pass a Node environmental variable using middleware? For example: NODE_ENV=production node index.js;Sabrasabre
You can read them from process.env.NODE_ENV (or whatever the variable is), and can set them the same way.Wallen
Thanks. I'll search for that in the documentation. It seems like learning Express is going to be a better way to move forward for anything beyond static file serving on the web with Node.js.Sabrasabre
FYI this has changed as of ghost 0.5.2 github.com/TryGhost/Ghost/wiki/…Gruchot
B
2

Assuming you have followed "Install from zip (fastest & best for bloggers)" from https://github.com/tryghost/Ghost and you are serving static content from /public/ with http-server.

My solution is to use Ghost's Express server to serve your content:

Download Ghost.zip and unzip at [path]/server/

Open up your Ghost's config.js file and change the url in development from http://localhost:2368 to http://localhost:2368/blog/

Now open open the index.js file in the same directory and add the following:

parentApp.use(express.static(__dirname + '/public'));

after: parentApp = express();

where '/public' is the directory containing your static content.

Now, if you go to: http://localhost:2368 you will find your website and your blog will be at http://localhost:2368/blog/

To change to production, you need to make the appropriate changes and start with NODE_ENV=production npm start. To change to port 80, you will only need to change the port inside config.js and this will serve both your site and the blog on 80. This will obviously give you insufficient permission issue and there's tonne of tutorials that show you how to setup Node.js on port 80 so follow that.

Blanket answered 19/1, 2015 at 5:44 Comment(2)
Thanks for the suggestion to use Express, but, like I commented to Paul, I'm looking for a direct answer to my question. I'm asking if it's possible to use http-server and run a Ghost blog simultaneously. And if so, how?Sabrasabre
Can you run two binaries on the same port? Ofcourse, not. Ghost already uses Express so that one line addition would serve your content as well. Express is obviously more powerful and complex than that. Anyhow, If you do not want to use Express, and want to do what http-server does, you can add the following in Ghost's index.js #7268533.Blanket

© 2022 - 2024 — McMap. All rights reserved.