How to mount Ghost on a subdirectory in express
Asked Answered
S

1

8

I have a an existing website built with express and I would like to add a "/blog" powered by Ghost. I've added Ghost to my dependencies, installed and configured the urls in Ghosts config to localhost:3000/blog, but now I'm having trouble.

In my app.js I've added the following lines:

var blog = require('./routes/blog');
app.use('/blog', blog);

My blog.js looks like this:

var express = require('express');
var router = express.Router();
var ghost = require('ghost');
ghost().then(function (ghostServer) {
    ghostServer.start();
});

router.get('/', ghost);

module.exports = router;

I'm pretty sure blog.js is incorrect.

Stentor answered 13/1, 2015 at 20:0 Comment(4)
have you had a look at this article?Cosmetician
Yes, I read that. Thanks though. I think it's related.Stentor
What's the problem?Oiler
This article about using ghost as middleware could solve the problem.Boarding
B
0

Node is very limited to do is, for cases when ghost is not configurable as express middleware, which I believe is the case here.

That leaves you with Loadbalancers and DNS as solutions to this problem. On something like HAPRoxy or Nginx you could make those recirects on the /blog route, would need to cater for scripts that the HTML requires to load and to redirect them too.

This might be also better practice since you seperate the concerns.

Burrill answered 16/5, 2017 at 10:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.