Carpetfizz
Carpetfizz

Reputation: 9149

Run Ghost in production mode, in existing node application

I am using Ghost in my existing Node.js application with the following configuration:

 // ### Development **(default)**
    development: {
        // The url to use when providing links to the site, E.g. in RSS and email.
        // Change this to your Ghost blogs published URL.
        url: 'http://localhost:2368/blog',

        database: {
            client: 'sqlite3',
            connection: {
                filename: path.join(__dirname, '/content/data/ghost-dev.db')
            },
            debug: false
        },
        server: {
            // Host to be passed to node's `net.Server#listen()`
            host: 'localhost',
            // Port to be passed to node's `net.Server#listen()`, for iisnode set this to `process.env.PORT`
            port: '2368'
        }
    }

However, I am deploying my application to Heroku with Postgresql, so I have a Production config here:

production: {
        url: 'https://summittalks.herokuapp.com:2368/blog',
        mail: {},
        database: {
            client: 'postgres',
            connection: {
                host: 'MY_HOST',
                user: 'MY_USER',
                password: 'MY_PASS',
                database: 'MY_DB',
                port: 'MY_PORT'
            },
            debug: false
        },

        server: {
            // Host to be passed to node's `net.Server#listen()`
            host: '0.0.0.0',
            // Port to be passed to node's `net.Server#listen()`, for iisnode set this to `process.env.PORT`
            port: '2368'
        },

        fileStorage: false
    }

I'm loading Ghost into my Node.js application like so:

app.modules.ghost({
    config: app.utilities.path.join(__dirname, '/ghost/ghost.js')
}).then(function(ghostServer){
    app.express.use(ghostServer.config.paths.subdir, ghostServer.rootApp);
    ghostServer.start(app.express);
}).then(function(req,res){
    app.express.get('*', function(req,res){
        res.status(404).send('<h1>404</h1><p>Page not found.</p>');
    });
    app.express.post('*', function(req,res){
        res.status(404).json({error:'Resource not found'});
    });
});

How can I run Ghost in production and tell Heroku to do so? I currently do:

node server.js dev

to run my application in dev mode. If the "dev" is not there, then my application runs in production mode. I want to apply a similar logic for Ghost, but I don't know how to tell it to run in prod.

Upvotes: 1

Views: 1388

Answers (1)

Carpetfizz
Carpetfizz

Reputation: 9149

Simply run this line in the root of your Heroku app directory:

$ heroku config:set NODE_ENV=production

Upvotes: 3

Related Questions