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:
parent
23fed961e5
commit
3459f38c09
3 changed files with 28 additions and 18 deletions
|
@ -1,11 +1,17 @@
|
||||||
const serialize = require('./serialize');
|
const serialize = require('./serialize');
|
||||||
|
const Promise = require('bluebird');
|
||||||
|
|
||||||
module.exports = (event, model) => {
|
module.exports = (event, model) => {
|
||||||
const payload = {};
|
const payload = {};
|
||||||
|
|
||||||
if (model) {
|
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);
|
||||||
};
|
};
|
||||||
|
|
|
@ -44,7 +44,7 @@ module.exports = (event, model) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
sequence(ops)
|
return sequence(ops)
|
||||||
.then((results) => {
|
.then((results) => {
|
||||||
const current = results[0];
|
const current = results[0];
|
||||||
const previous = results[1];
|
const previous = results[1];
|
||||||
|
|
|
@ -68,23 +68,27 @@ module.exports = (event, model) => {
|
||||||
debug(`${webhooks.models.length} webhooks found for ${event}.`);
|
debug(`${webhooks.models.length} webhooks found for ${event}.`);
|
||||||
|
|
||||||
_.each(webhooks.models, (webhook) => {
|
_.each(webhooks.models, (webhook) => {
|
||||||
const reqPayload = JSON.stringify(payload(webhook.get('event'), model));
|
payload(webhook.get('event'), model)
|
||||||
const url = webhook.get('target_url');
|
.then((payload) => {
|
||||||
const opts = {
|
console.log(payload);
|
||||||
body: reqPayload,
|
const reqPayload = JSON.stringify(payload);
|
||||||
headers: {
|
const url = webhook.get('target_url');
|
||||||
'Content-Length': Buffer.byteLength(reqPayload),
|
const opts = {
|
||||||
'Content-Type': 'application/json'
|
body: reqPayload,
|
||||||
},
|
headers: {
|
||||||
timeout: 2 * 1000,
|
'Content-Length': Buffer.byteLength(reqPayload),
|
||||||
retries: 5
|
'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)
|
request(url, opts)
|
||||||
.then(response.onSuccess(webhook))
|
.then(response.onSuccess(webhook))
|
||||||
.catch(response.onError(webhook));
|
.catch(response.onError(webhook));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue