Webhooks with Express.js not works properly

Hi! I recently read ghost’s documentation about it’s webhooks and I decided to try it out. I set up a simple express app for this purpose, here is the code:

const express = require('express');
const app = express();
const cors = require('cors');

app.use(cors({origin: ['http://localhost:2368']}));


app.post('/', (req, res) => {
    console.log(req.body);
    res.send()
});

app.listen(3000);

In Ghost Admin I created a custom integration with the following parameters:

Title: BulkMailer
//API keys omitted
API URL: http://localhost:2368

Webhook:

Post published
Target URL: http://localhost:3000
Secret: // i left it empty

After I created a post in ghost, my express endpoint was hit, but the body was undefined.

Ghost logs:

"msg":"Request to http://localhost:3000 failed because of: ETIMEDOUT."

Any idea?

The endpoint needs a 20x status code to know it worked.

1 Like

I updated my endpoint with res.sendStatus(200);, but nothing changed.

That should remove or change the ghost error - did it?

I think you need to process the body with .json? See the first answer here

2 Likes

Awesome man. Adding app.use(express.json()) fixed it. Thank you a lot!

2 Likes