mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-23 02:41:50 +03:00
fcd275f6c0
refs #9866 - Moved web/middleware to web/shared/middlewares - Moved util file to web/shared/utils
30 lines
797 B
JavaScript
30 lines
797 B
JavaScript
const api = require('../../../api');
|
|
const labs = require('../../../services/labs');
|
|
const common = require('../../../lib/common');
|
|
|
|
module.exports = function getFrontendClient(req, res, next) {
|
|
if (labs.isSet('publicAPI') !== true) {
|
|
return next();
|
|
}
|
|
|
|
return api.clients
|
|
.read({slug: 'ghost-frontend'})
|
|
.then((client) => {
|
|
client = client.clients[0];
|
|
|
|
if (client.status === 'enabled') {
|
|
res.locals.client = {
|
|
id: client.slug,
|
|
secret: client.secret
|
|
};
|
|
}
|
|
|
|
next();
|
|
})
|
|
.catch((err) => {
|
|
// Log the error, but carry on as this is non-critical
|
|
common.logging.error(err);
|
|
next();
|
|
});
|
|
};
|