Question

I'm trying to setup the Ghost blogging program (v0.4) in a subdirectory of another nodejs/express app. I was able to get it working following the steps outlined here: Node http-proxy and express

So, I setup the proxy to Ghost from my main app via Express like this (on my dev machine):'

var proxy = new httpProxy.createProxyServer();
server.get('/blog*', function (req, res, next) {
    proxy.web(req, res, {
        target: 'http://localhost:2368'
    });
});

This works to access the blog content. However, when I go to /blog/ghost/signin and try to login, I get a 404. As far as I can tell, the signin page doesn't go anywhere outside of the blog/ directory, so why would it fail?

If I view the blog directly (on port 2368), I can login just fine.

Was it helpful?

Solution

You have defined a route for GET only, so you are only proxying GET requests, but login and signup uses a POST request. Usually a proxy rule in Apache or nginx will proxy all allowed methods for a given url, but since you defining the handler by method this doesn't happen.

The signup POST gets a 404 since it is handled by your first node application that doesn't know what to do.

In addition to POST you also need the DELETE method to be able click on the notification messages and to delete posts. I'm not sure if other methods are needed as well (OPTIONS), GET, POST and DELETE were the only ones I observed, you will see which method is failing if you take a look at the requests the page does e.g. with Firebug.

To fix this, add the same handler you have added with get for post,put and delete as well:

server.post('/blog*', function (req, res, next) {
    proxy.web(req, res, {
        target: 'http://localhost:2368'
    });
});
server.delete('/blog*', function (req, res, next) {
    proxy.web(req, res, {
        target: 'http://localhost:2368'
    });
});
server.put('/blog*', function (req, res, next) {
    proxy.web(req, res, {
        target: 'http://localhost:2368'
    });
});

This way, the admin interface works correct.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top