Ghost/core/server/services/members/index.js
Rishabh Garg 876e310aea
Updated check for members-ssr use at theme layer (#10693)
no issue

### Context

As part of updating the theme layer to use members-ssr [here](f9899cb8c4), we introduced a case where if `enableDeveloperExperiments` is not switched on, the whole theme loading will crash due to unavailability of `ssr` property on members service [here](https://github.com/TryGhost/Ghost/blob/master/core/server/services/members/index.js#L12). Since we switch on `enableDeveloperExperiments` by default on master now, the issue won't be reproducible locally until explicitly switched off. 

This PR includes a patch fix which adds dummy `ssr` object to members service `api` object and members middleware check on APIs to ensure no crash in case developer flags is not switched on. 

Longer term it will be definitely useful to upgrade the dummy `api` object to trigger on member labs than the developer flag.
2019-04-17 17:38:12 +05:30

30 lines
1.1 KiB
JavaScript

const config = require('../../config/index.js');
const common = require('../../lib/common');
module.exports = {
get api() {
if (!config.get('enableDeveloperExperiments')) {
return {
apiRouter: function (req, res, next) {
return next(new common.errors.NotFoundError());
},
staticRouter: function (req, res, next) {
return next(new common.errors.NotFoundError());
},
ssr: {
exchangeTokenForSession: function (req, res) {
return Promise.reject(new common.errors.InternalServerError());
},
deleteSession: function (req, res) {
return Promise.reject(new common.errors.InternalServerError());
},
getMemberDataFromSession: function (req, res) {
return Promise.reject(new common.errors.InternalServerError());
}
}
};
}
return require('./api');
}
};