mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
409dc3b534
refs: https://github.com/TryGhost/Team/issues/1599
refs: f3d5d9cf6b
- this commit adds the concept of a frontend data service, intended for passing data to the frontend from the server in a clean way. This is the start of a new & improved pattern, to hopefully reduce coupling
- the newly added internal frontend key is then exposed through this pattern so that the frontend can make use of it
- the first use case is so that portal can use it to talk to the content API instead of having weird endpoints for portal
- this key will also be used by other internal scripts in future, it's public and therefore safe to expose, but it's meant for internal use only and therefore is not exposed in a generic way e.g. as a helper
27 lines
792 B
JavaScript
27 lines
792 B
JavaScript
const errors = require('@tryghost/errors');
|
|
const logging = require('@tryghost/logging');
|
|
|
|
class FrontendDataService {
|
|
constructor({IntegrationModel}) {
|
|
this.IntegrationModel = IntegrationModel;
|
|
this.frontendKey = null;
|
|
}
|
|
|
|
async getFrontendKey() {
|
|
if (this.frontendKey) {
|
|
return this.frontendKey;
|
|
}
|
|
|
|
try {
|
|
const key = await this.IntegrationModel.getInternalFrontendKey();
|
|
this.frontendKey = key.toJSON().api_keys[0].secret;
|
|
} catch (error) {
|
|
this.frontendKey = null;
|
|
logging.error(new errors.InternalServerError({message: 'Unable to find the internal frontend key', err: error}));
|
|
}
|
|
|
|
return this.frontendKey;
|
|
}
|
|
}
|
|
|
|
module.exports = FrontendDataService;
|