mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Removed res.locals.apiVersion
- we are getting rid of the concept of having multiple api versions in a single ghost install - we no longer need to pass the apiVersion around using res.locals - To simplify code that uses our frontend proxy the proxy now _only_ exposes canary
This commit is contained in:
parent
4332546a56
commit
8bd9169298
21 changed files with 86 additions and 141 deletions
|
@ -134,7 +134,7 @@ module.exports = function get(resource, options) {
|
|||
const start = Date.now();
|
||||
const data = createFrame(options.data);
|
||||
const ghostGlobals = _.omit(data, ['_parent', 'root']);
|
||||
const apiVersion = _.get(data, 'root._locals.apiVersion');
|
||||
|
||||
let apiOptions = options.hash;
|
||||
let returnedRowsCount;
|
||||
|
||||
|
@ -151,7 +151,7 @@ module.exports = function get(resource, options) {
|
|||
}
|
||||
|
||||
const controllerName = RESOURCES[resource].alias;
|
||||
const controller = api[apiVersion][controllerName];
|
||||
const controller = api[controllerName];
|
||||
const action = isBrowse(apiOptions) ? 'browse' : 'read';
|
||||
|
||||
// Parse the options we're going to pass to the API
|
||||
|
@ -194,7 +194,7 @@ module.exports = function get(resource, options) {
|
|||
message: `{{#get}} helper took ${totalMs}ms to complete`,
|
||||
code: 'SLOW_GET_HELPER',
|
||||
errorDetails: {
|
||||
api: `${apiVersion}.${controllerName}.${action}`,
|
||||
api: `${controllerName}.${action}`,
|
||||
apiOptions,
|
||||
returnedRows: returnedRowsCount
|
||||
}
|
||||
|
|
|
@ -58,10 +58,9 @@ const buildApiOptions = function buildApiOptions(options, post) {
|
|||
const fetch = function fetch(options, data) {
|
||||
const self = this;
|
||||
const apiOptions = buildApiOptions(options, this);
|
||||
const apiVersion = data.root._locals.apiVersion;
|
||||
|
||||
// @TODO: https://github.com/TryGhost/Ghost/issues/10548
|
||||
const controller = api[apiVersion].postsPublic || api[apiVersion].posts;
|
||||
const controller = api.postsPublic || api.posts;
|
||||
|
||||
return controller
|
||||
.browse(apiOptions)
|
||||
|
|
|
@ -14,7 +14,7 @@ const routeMatch = require('path-match')();
|
|||
function entryLookup(postUrl, routerOptions, locals) {
|
||||
debug(postUrl);
|
||||
|
||||
const api = require('../proxy').api[locals.apiVersion];
|
||||
const api = require('../proxy').api;
|
||||
const targetPath = url.parse(postUrl).path;
|
||||
const permalinks = routerOptions.permalinks;
|
||||
let isEditURL = false;
|
||||
|
|
|
@ -45,7 +45,7 @@ defaultPostQuery.options = defaultQueryOptions.options;
|
|||
* @returns {Promise}
|
||||
*/
|
||||
function processQuery(query, slugParam, locals) {
|
||||
const api = require('../proxy').api[locals.apiVersion];
|
||||
const api = require('../proxy').api;
|
||||
|
||||
query = _.cloneDeep(query);
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ module.exports = {
|
|||
settingsCache: settingsCache,
|
||||
|
||||
// TODO: Expose less of the API to make this safe
|
||||
api: require('../../server/api'),
|
||||
api: require('../../server/api').canary,
|
||||
|
||||
// Labs utils for enabling/disabling helpers
|
||||
labs: require('../../shared/labs'),
|
||||
|
|
|
@ -14,7 +14,7 @@ const renderer = require('../../rendering');
|
|||
module.exports = function emailPostController(req, res, next) {
|
||||
debug('emailPostController');
|
||||
|
||||
const api = require('../../proxy').api[res.locals.apiVersion];
|
||||
const api = require('../../proxy').api;
|
||||
|
||||
const params = {
|
||||
uuid: req.params.uuid,
|
||||
|
@ -51,9 +51,7 @@ module.exports = function emailPostController(req, res, next) {
|
|||
return urlUtils.redirect301(res, routerManager.getUrlByResourceId(post.id, {withSubdirectory: true}));
|
||||
}
|
||||
|
||||
if (res.locals.apiVersion !== 'v0.1' && res.locals.apiVersion !== 'v2') {
|
||||
post.access = !!post.html;
|
||||
}
|
||||
|
||||
// @TODO: See renderer/secure
|
||||
renderer.secure(req, post);
|
||||
|
|
|
@ -14,7 +14,7 @@ const renderer = require('../../rendering');
|
|||
module.exports = function previewController(req, res, next) {
|
||||
debug('previewController');
|
||||
|
||||
const api = require('../../proxy').api[res.locals.apiVersion];
|
||||
const api = require('../../proxy').api;
|
||||
|
||||
const params = {
|
||||
uuid: req.params.uuid,
|
||||
|
@ -53,9 +53,7 @@ module.exports = function previewController(req, res, next) {
|
|||
return urlUtils.redirect301(res, routerManager.getUrlByResourceId(post.id, {withSubdirectory: true}));
|
||||
}
|
||||
|
||||
if (res.locals.apiVersion !== 'v0.1' && res.locals.apiVersion !== 'v2') {
|
||||
post.access = !!post.html;
|
||||
}
|
||||
|
||||
// @TODO: See renderer/secure
|
||||
renderer.secure(req, post);
|
||||
|
|
|
@ -4,7 +4,7 @@ const debug = require('@tryghost/debug')('services:routing:controllers:static');
|
|||
const renderer = require('../../rendering');
|
||||
|
||||
function processQuery(query, locals) {
|
||||
const api = require('../../proxy').api[locals.apiVersion];
|
||||
const api = require('../../proxy').api;
|
||||
query = _.cloneDeep(query);
|
||||
|
||||
// CASE: If you define a single data key for a static route (e.g. data: page.team), this static route will represent
|
||||
|
|
|
@ -47,7 +47,7 @@ function calculateLegacyPriceData(products) {
|
|||
|
||||
async function getProductAndPricesData() {
|
||||
try {
|
||||
const page = await api.canary.productsPublic.browse({
|
||||
const page = await api.productsPublic.browse({
|
||||
include: ['monthly_price', 'yearly_price', 'benefits'],
|
||||
limit: 'all',
|
||||
filter: 'active:true'
|
||||
|
|
|
@ -190,8 +190,8 @@ module.exports = {
|
|||
*
|
||||
* @NOTE:
|
||||
*
|
||||
* Please create separate controllers for Content & Admin API. The goal is to expose `api.canary.content` and
|
||||
* `api.canary.admin` soon. Need to figure out how serializers & validation works then.
|
||||
* Please create separate controllers for Content & Admin API. The goal is to expose `api.content` and
|
||||
* `api.admin` soon. Need to figure out how serializers & validation works then.
|
||||
*/
|
||||
get pagesPublic() {
|
||||
return shared.pipeline(require('./pages-public'), localUtils, 'content');
|
||||
|
|
|
@ -11,8 +11,6 @@ module.exports = function ghostLocals(req, res, next) {
|
|||
res.locals.safeVersion = ghostVersion.safe;
|
||||
// relative path from the URL
|
||||
res.locals.relativeUrl = req.path;
|
||||
// @TODO: remove
|
||||
res.locals.apiVersion = 'canary';
|
||||
|
||||
next();
|
||||
};
|
||||
|
|
|
@ -3,7 +3,6 @@ const sinon = require('sinon');
|
|||
const testUtils = require('../../utils');
|
||||
const models = require('../../../core/server/models/index');
|
||||
|
||||
const API_VERSION = 'canary';
|
||||
const DEFAULT_POST_FIXTURE_COUNT = 7;
|
||||
|
||||
const get = require('../../../core/frontend/helpers/get');
|
||||
|
@ -94,7 +93,7 @@ describe('e2e {{#get}} helper', function () {
|
|||
beforeEach(function () {
|
||||
fn = sinon.spy();
|
||||
inverse = sinon.spy();
|
||||
locals = {root: {_locals: {apiVersion: API_VERSION}}};
|
||||
locals = {root: {_locals: {}}};
|
||||
});
|
||||
|
||||
describe('{{access}} property', function () {
|
||||
|
@ -102,7 +101,7 @@ describe('e2e {{#get}} helper', function () {
|
|||
|
||||
it('not authenticated member', async function () {
|
||||
member = null;
|
||||
locals = {root: {_locals: {apiVersion: API_VERSION}}, member};
|
||||
locals = {root: {_locals: {}}, member};
|
||||
await get.call(
|
||||
{},
|
||||
'posts',
|
||||
|
@ -126,7 +125,7 @@ describe('e2e {{#get}} helper', function () {
|
|||
|
||||
it('free member', async function () {
|
||||
member = buildMember('free');
|
||||
locals = {root: {_locals: {apiVersion: API_VERSION}}, member};
|
||||
locals = {root: {_locals: {}}, member};
|
||||
await get.call(
|
||||
{},
|
||||
'posts',
|
||||
|
@ -150,7 +149,7 @@ describe('e2e {{#get}} helper', function () {
|
|||
|
||||
it('paid member', async function () {
|
||||
member = buildMember('paid');
|
||||
locals = {root: {_locals: {apiVersion: API_VERSION}}, member};
|
||||
locals = {root: {_locals: {}}, member};
|
||||
await get.call(
|
||||
{},
|
||||
'posts',
|
||||
|
@ -174,7 +173,7 @@ describe('e2e {{#get}} helper', function () {
|
|||
|
||||
it('comped member', async function () {
|
||||
member = buildMember('comped');
|
||||
locals = {root: {_locals: {apiVersion: API_VERSION}}, member};
|
||||
locals = {root: {_locals: {}}, member};
|
||||
await get.call(
|
||||
{},
|
||||
'posts',
|
||||
|
@ -207,7 +206,7 @@ describe('e2e {{#get}} helper', function () {
|
|||
active: true
|
||||
}]);
|
||||
|
||||
locals = {root: {_locals: {apiVersion: API_VERSION}}, member};
|
||||
locals = {root: {_locals: {}}, member};
|
||||
await get.call(
|
||||
{},
|
||||
'posts',
|
||||
|
@ -237,7 +236,7 @@ describe('e2e {{#get}} helper', function () {
|
|||
active: true
|
||||
}]);
|
||||
|
||||
locals = {root: {_locals: {apiVersion: API_VERSION}}, member};
|
||||
locals = {root: {_locals: {}}, member};
|
||||
await get.call(
|
||||
{},
|
||||
'posts',
|
||||
|
@ -267,7 +266,7 @@ describe('e2e {{#get}} helper', function () {
|
|||
active: true
|
||||
}]);
|
||||
|
||||
locals = {root: {_locals: {apiVersion: API_VERSION}}, member};
|
||||
locals = {root: {_locals: {}}, member};
|
||||
await get.call(
|
||||
{},
|
||||
'posts',
|
||||
|
|
|
@ -3,8 +3,6 @@ const sinon = require('sinon');
|
|||
const testUtils = require('../../utils');
|
||||
const models = require('../../../core/server/models/index');
|
||||
|
||||
const API_VERSION = 'canary';
|
||||
|
||||
const next_post = require('../../../core/frontend/helpers/prev_post');
|
||||
|
||||
async function createPost(data) {
|
||||
|
@ -91,9 +89,6 @@ describe('e2e {{#next_post}} helper', function () {
|
|||
const member = null;
|
||||
const locals = {
|
||||
root: {
|
||||
_locals: {
|
||||
apiVersion: API_VERSION
|
||||
},
|
||||
context: ['post']
|
||||
},
|
||||
member
|
||||
|
@ -137,9 +132,6 @@ describe('e2e {{#next_post}} helper', function () {
|
|||
const member = buildMember('free');
|
||||
const locals = {
|
||||
root: {
|
||||
_locals: {
|
||||
apiVersion: API_VERSION
|
||||
},
|
||||
context: ['post']
|
||||
},
|
||||
member
|
||||
|
@ -183,9 +175,6 @@ describe('e2e {{#next_post}} helper', function () {
|
|||
const member = buildMember('paid');
|
||||
const locals = {
|
||||
root: {
|
||||
_locals: {
|
||||
apiVersion: API_VERSION
|
||||
},
|
||||
context: ['post']
|
||||
},
|
||||
member
|
||||
|
@ -235,9 +224,6 @@ describe('e2e {{#next_post}} helper', function () {
|
|||
|
||||
const locals = {
|
||||
root: {
|
||||
_locals: {
|
||||
apiVersion: API_VERSION
|
||||
},
|
||||
context: ['post']
|
||||
},
|
||||
member
|
||||
|
@ -287,9 +273,6 @@ describe('e2e {{#next_post}} helper', function () {
|
|||
|
||||
const locals = {
|
||||
root: {
|
||||
_locals: {
|
||||
apiVersion: API_VERSION
|
||||
},
|
||||
context: ['post']
|
||||
},
|
||||
member
|
||||
|
|
|
@ -5,14 +5,9 @@ const {SafeString} = require('../../../../core/frontend/services/handlebars');
|
|||
|
||||
// Stuff we are testing
|
||||
const get = require('../../../../core/frontend/helpers/get');
|
||||
|
||||
const models = require('../../../../core/server/models');
|
||||
|
||||
const proxy = require('../../../../core/frontend/services/proxy');
|
||||
|
||||
const API_VERSION = 'canary';
|
||||
|
||||
const api = require('../../../../core/server/api')[API_VERSION];
|
||||
const api = require('../../../../core/server/api').canary;
|
||||
|
||||
describe('{{#get}} helper', function () {
|
||||
let fn;
|
||||
|
@ -27,7 +22,7 @@ describe('{{#get}} helper', function () {
|
|||
fn = sinon.spy();
|
||||
inverse = sinon.spy();
|
||||
|
||||
locals = {root: {_locals: {apiVersion: API_VERSION}}, globalProp: {foo: 'bar'}};
|
||||
locals = {root: {}, globalProp: {foo: 'bar'}};
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
|
@ -39,7 +34,7 @@ describe('{{#get}} helper', function () {
|
|||
const meta = {pagination: {}};
|
||||
|
||||
beforeEach(function () {
|
||||
locals = {root: {_locals: {apiVersion: 'canary'}}};
|
||||
locals = {root: {_locals: {}}};
|
||||
|
||||
browsePostsStub = sinon.stub(api, 'postsPublic').get(() => {
|
||||
return {
|
||||
|
@ -64,12 +59,12 @@ describe('{{#get}} helper', function () {
|
|||
});
|
||||
});
|
||||
|
||||
describe('authors canary', function () {
|
||||
describe('authors', function () {
|
||||
let browseAuthorsStub;
|
||||
const meta = {pagination: {}};
|
||||
|
||||
beforeEach(function () {
|
||||
locals = {root: {_locals: {apiVersion: API_VERSION}}};
|
||||
locals = {root: {_locals: {}}};
|
||||
|
||||
browseAuthorsStub = sinon.stub(api, 'authorsPublic').get(() => {
|
||||
return {
|
||||
|
@ -274,7 +269,7 @@ describe('{{#get}} helper', function () {
|
|||
});
|
||||
|
||||
it('Behaves normally without config', async function () {
|
||||
locals = {root: {_locals: {apiVersion: API_VERSION}}};
|
||||
locals = {root: {_locals: {}}};
|
||||
await get.call(
|
||||
{},
|
||||
'posts',
|
||||
|
@ -286,7 +281,7 @@ describe('{{#get}} helper', function () {
|
|||
it('Replaces "all" with "getHelperLimitAllMax" config, if present', async function () {
|
||||
sinon.stub(proxy.config, 'get').withArgs('getHelperLimitAllMax').returns(2);
|
||||
|
||||
locals = {root: {_locals: {apiVersion: API_VERSION}}};
|
||||
locals = {root: {_locals: {}}};
|
||||
await get.call(
|
||||
{},
|
||||
'posts',
|
||||
|
@ -315,7 +310,7 @@ describe('{{#get}} helper', function () {
|
|||
});
|
||||
|
||||
it('should pass the member context', async function () {
|
||||
locals = {root: {_locals: {apiVersion: API_VERSION}}, member};
|
||||
locals = {root: {_locals: {}}, member};
|
||||
await get.call(
|
||||
{},
|
||||
'posts',
|
||||
|
|
|
@ -7,16 +7,13 @@ const api = require('../../../../core/server/api');
|
|||
const should = require('should');
|
||||
|
||||
describe('{{next_post}} helper', function () {
|
||||
const apiVersion = 'canary';
|
||||
let locals;
|
||||
let browsePostsStub;
|
||||
|
||||
beforeEach(function () {
|
||||
locals = {
|
||||
root: {
|
||||
_locals: {
|
||||
apiVersion: apiVersion
|
||||
},
|
||||
_locals: {},
|
||||
context: ['post']
|
||||
}
|
||||
};
|
||||
|
@ -130,9 +127,7 @@ describe('{{next_post}} helper', function () {
|
|||
beforeEach(function () {
|
||||
locals = {
|
||||
root: {
|
||||
_locals: {
|
||||
apiVersion: apiVersion
|
||||
},
|
||||
_locals: {},
|
||||
context: ['page']
|
||||
}
|
||||
};
|
||||
|
@ -169,9 +164,6 @@ describe('{{next_post}} helper', function () {
|
|||
beforeEach(function () {
|
||||
locals = {
|
||||
root: {
|
||||
_locals: {
|
||||
apiVersion: apiVersion
|
||||
},
|
||||
context: ['preview', 'post']
|
||||
}
|
||||
};
|
||||
|
@ -413,9 +405,7 @@ describe('{{next_post}} helper', function () {
|
|||
});
|
||||
locals = {
|
||||
root: {
|
||||
_locals: {
|
||||
apiVersion: apiVersion
|
||||
},
|
||||
_locals: {},
|
||||
context: ['post']
|
||||
},
|
||||
member
|
||||
|
|
|
@ -7,16 +7,13 @@ const api = require('../../../../core/server/api');
|
|||
const should = require('should');
|
||||
|
||||
describe('{{prev_post}} helper', function () {
|
||||
const apiVersion = 'canary';
|
||||
let browsePostsStub;
|
||||
let locals;
|
||||
|
||||
beforeEach(function () {
|
||||
locals = {
|
||||
root: {
|
||||
_locals: {
|
||||
apiVersion: apiVersion
|
||||
},
|
||||
_locals: {},
|
||||
context: ['post']
|
||||
}
|
||||
};
|
||||
|
@ -131,9 +128,7 @@ describe('{{prev_post}} helper', function () {
|
|||
beforeEach(function () {
|
||||
locals = {
|
||||
root: {
|
||||
_locals: {
|
||||
apiVersion: apiVersion
|
||||
},
|
||||
_locals: {},
|
||||
context: ['page']
|
||||
}
|
||||
};
|
||||
|
@ -171,9 +166,7 @@ describe('{{prev_post}} helper', function () {
|
|||
beforeEach(function () {
|
||||
locals = {
|
||||
root: {
|
||||
_locals: {
|
||||
apiVersion: apiVersion
|
||||
},
|
||||
_locals: {},
|
||||
context: ['preview', 'post']
|
||||
}
|
||||
};
|
||||
|
@ -416,9 +409,7 @@ describe('{{prev_post}} helper', function () {
|
|||
});
|
||||
locals = {
|
||||
root: {
|
||||
_locals: {
|
||||
apiVersion: apiVersion
|
||||
},
|
||||
_locals: {},
|
||||
context: ['post']
|
||||
},
|
||||
member
|
||||
|
|
|
@ -48,7 +48,7 @@ describe('Unit - frontend/data/entry-lookup', function () {
|
|||
};
|
||||
});
|
||||
|
||||
locals = {apiVersion: API_VERSION};
|
||||
locals = {};
|
||||
});
|
||||
|
||||
it('ensure pages controller is triggered', function () {
|
||||
|
@ -99,7 +99,7 @@ describe('Unit - frontend/data/entry-lookup', function () {
|
|||
};
|
||||
});
|
||||
|
||||
locals = {apiVersion: API_VERSION};
|
||||
locals = {};
|
||||
});
|
||||
|
||||
it('ensure posts controller is triggered', function () {
|
||||
|
|
|
@ -49,7 +49,7 @@ describe('Unit - frontend/data/fetch-data', function () {
|
|||
};
|
||||
});
|
||||
|
||||
locals = {apiVersion: API_VERSION};
|
||||
locals = {};
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
|
|
|
@ -50,9 +50,7 @@ describe('Unit - services/routing/controllers/preview', function () {
|
|||
routerOptions: {
|
||||
query: {controller: 'preview', resource: 'preview'}
|
||||
},
|
||||
locals: {
|
||||
apiVersion: 'canary'
|
||||
},
|
||||
locals: {},
|
||||
render: sinon.spy(),
|
||||
redirect: sinon.spy(),
|
||||
set: sinon.spy()
|
||||
|
|
|
@ -74,9 +74,7 @@ describe('Unit - services/routing/controllers/static', function () {
|
|||
routerOptions: {},
|
||||
render: sinon.spy(),
|
||||
redirect: sinon.spy(),
|
||||
locals: {
|
||||
apiVersion: API_VERSION
|
||||
}
|
||||
locals: {}
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
@ -26,9 +26,7 @@ describe('Theme Handler', function () {
|
|||
res.locals.should.be.an.Object();
|
||||
should.exist(res.locals.version);
|
||||
should.exist(res.locals.safeVersion);
|
||||
should.exist(res.locals.apiVersion);
|
||||
res.locals.relativeUrl.should.equal(req.path);
|
||||
res.locals.apiVersion.should.equal('canary');
|
||||
next.called.should.be.true();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue