2018-09-20 21:04:34 +03:00
|
|
|
const api = require('../../../api');
|
|
|
|
const labs = require('../../../services/labs');
|
|
|
|
const common = require('../../../lib/common');
|
2017-10-26 13:03:53 +03:00
|
|
|
|
|
|
|
module.exports = function getFrontendClient(req, res, next) {
|
|
|
|
if (labs.isSet('publicAPI') !== true) {
|
|
|
|
return next();
|
|
|
|
}
|
|
|
|
|
|
|
|
return api.clients
|
|
|
|
.read({slug: 'ghost-frontend'})
|
2018-09-20 16:03:33 +03:00
|
|
|
.then((client) => {
|
2017-10-26 13:03:53 +03:00
|
|
|
client = client.clients[0];
|
|
|
|
|
|
|
|
if (client.status === 'enabled') {
|
|
|
|
res.locals.client = {
|
|
|
|
id: client.slug,
|
|
|
|
secret: client.secret
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
next();
|
|
|
|
})
|
2018-09-20 16:03:33 +03:00
|
|
|
.catch((err) => {
|
2017-10-26 13:03:53 +03:00
|
|
|
// Log the error, but carry on as this is non-critical
|
2017-12-12 00:47:46 +03:00
|
|
|
common.logging.error(err);
|
2017-10-26 13:03:53 +03:00
|
|
|
next();
|
|
|
|
});
|
|
|
|
};
|