2017-12-06 17:37:54 +01:00
|
|
|
var api = require('../../api'),
|
2017-12-14 03:01:23 +01:00
|
|
|
labs = require('../../services/labs'),
|
2017-12-11 22:47:46 +01:00
|
|
|
common = require('../../lib/common');
|
2017-10-26 12:03:53 +02:00
|
|
|
|
|
|
|
module.exports = function getFrontendClient(req, res, next) {
|
|
|
|
if (labs.isSet('publicAPI') !== true) {
|
|
|
|
return next();
|
|
|
|
}
|
|
|
|
|
|
|
|
return api.clients
|
|
|
|
.read({slug: 'ghost-frontend'})
|
|
|
|
.then(function handleClient(client) {
|
|
|
|
client = client.clients[0];
|
|
|
|
|
|
|
|
if (client.status === 'enabled') {
|
|
|
|
res.locals.client = {
|
|
|
|
id: client.slug,
|
|
|
|
secret: client.secret
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
next();
|
|
|
|
})
|
|
|
|
.catch(function (err) {
|
|
|
|
// Log the error, but carry on as this is non-critical
|
2017-12-11 22:47:46 +01:00
|
|
|
common.logging.error(err);
|
2017-10-26 12:03:53 +02:00
|
|
|
next();
|
|
|
|
});
|
|
|
|
};
|