0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Fixed webhook payload

no issue

- async code was not handled
This commit is contained in:
kirrg001 2019-02-25 09:38:08 +01:00
parent 23fed961e5
commit 3459f38c09
3 changed files with 28 additions and 18 deletions

View file

@ -1,11 +1,17 @@
const serialize = require('./serialize');
const Promise = require('bluebird');
module.exports = (event, model) => {
const payload = {};
if (model) {
Object.assign(payload, serialize(event, model));
return serialize(event, model)
.then((result) => {
Object.assign(payload, result);
return payload;
});
}
return payload;
return Promise.resolve(payload);
};

View file

@ -44,7 +44,7 @@ module.exports = (event, model) => {
});
}
sequence(ops)
return sequence(ops)
.then((results) => {
const current = results[0];
const previous = results[1];

View file

@ -68,23 +68,27 @@ module.exports = (event, model) => {
debug(`${webhooks.models.length} webhooks found for ${event}.`);
_.each(webhooks.models, (webhook) => {
const reqPayload = JSON.stringify(payload(webhook.get('event'), model));
const url = webhook.get('target_url');
const opts = {
body: reqPayload,
headers: {
'Content-Length': Buffer.byteLength(reqPayload),
'Content-Type': 'application/json'
},
timeout: 2 * 1000,
retries: 5
};
payload(webhook.get('event'), model)
.then((payload) => {
console.log(payload);
const reqPayload = JSON.stringify(payload);
const url = webhook.get('target_url');
const opts = {
body: reqPayload,
headers: {
'Content-Length': Buffer.byteLength(reqPayload),
'Content-Type': 'application/json'
},
timeout: 2 * 1000,
retries: 5
};
common.logging.info(`Trigger Webhook for "${webhook.get('event')}" with url "${url}".`);
common.logging.info(`Trigger Webhook for "${webhook.get('event')}" with url "${url}".`);
request(url, opts)
.then(response.onSuccess(webhook))
.catch(response.onError(webhook));
request(url, opts)
.then(response.onSuccess(webhook))
.catch(response.onError(webhook));
});
});
});
};