mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
30 lines
785 B
JavaScript
30 lines
785 B
JavaScript
|
var api = require('../api'),
|
||
|
labs = require('../utils/labs'),
|
||
|
logging = require('../logging');
|
||
|
|
||
|
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
|
||
|
logging.error(err);
|
||
|
next();
|
||
|
});
|
||
|
};
|