Ghost/core/server/middleware/frontend-client.js
Katharina Irrgang 88eab9898c Moved fetching client out of our ghost_head helper (#9180)
refs #8995

- move the getClient lookup from ghost_head into middleware
- use res.locals to keep track of the information (res.locals.client)
- make the middleware global to all frontend routes
- ghost_head: get locals from options.data not this (!)
- adapt lot's of tests
2017-10-26 12:03:53 +02:00

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();
});
};