mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Updated method getApiPath
to take options as param
Refs #9936 - Updated method to take single options param with version and admin instead of separate values - Updated urlFor method to use the updated syntax - Updated parent-app to use updated syntax
This commit is contained in:
parent
fd84565218
commit
a49bbfb9d6
2 changed files with 13 additions and 9 deletions
|
@ -11,13 +11,16 @@ const moment = require('moment-timezone'),
|
|||
|
||||
/**
|
||||
* Returns API path combining base path and path for specific version asked or deprecated by default
|
||||
* @param {string} version version for which to get the path(stable, actice, deprecated: content, admin), defaults to deprecated:content
|
||||
* @param {Object} options {version} for which to get the path(stable, actice, deprecated),
|
||||
* {type} admin|content: defaults to {version: deprecated, type: content}
|
||||
* @return {string} API Path for version
|
||||
*/
|
||||
function getApiPath(version = 'deprecated', admin = false) {
|
||||
function getApiPath(options) {
|
||||
const apiVersions = config.get('api:versions');
|
||||
let versionType = apiVersions[version] || apiVersions.deprecated;
|
||||
let versionPath = admin ? versionType.admin : versionType.content;
|
||||
let version = options.version || 'deprecated';
|
||||
let type = options.type || 'content';
|
||||
let versionData = apiVersions[version];
|
||||
let versionPath = versionData[type];
|
||||
return `${BASE_API_PATH}${versionPath}/`;
|
||||
}
|
||||
|
||||
|
@ -313,7 +316,7 @@ function urlFor(context, data, absolute) {
|
|||
}
|
||||
} else if (context === 'api') {
|
||||
urlPath = getAdminUrl() || getBlogUrl();
|
||||
let apiPath = getApiPath('deprecated');
|
||||
let apiPath = getApiPath({version: 'deprecated', type: 'content'});
|
||||
// CASE: with or without protocol? If your blog url (or admin url) is configured to http, it's still possible that e.g. nginx allows both https+http.
|
||||
// So it depends how you serve your blog. The main focus here is to avoid cors problems.
|
||||
// @TODO: rename cors
|
||||
|
@ -324,7 +327,8 @@ function urlFor(context, data, absolute) {
|
|||
}
|
||||
|
||||
if (data && data.version) {
|
||||
apiPath = getApiPath(data.version, data.admin);
|
||||
let versionType = data.admin ? 'admin' : 'content';
|
||||
apiPath = getApiPath({version: data.version, type: versionType});
|
||||
}
|
||||
|
||||
if (absolute) {
|
||||
|
|
|
@ -39,9 +39,9 @@ module.exports = function setupParentApp(options = {}) {
|
|||
// API
|
||||
// @TODO: finish refactoring the API app
|
||||
// @TODO: decide what to do with these paths - config defaults? config overrides?
|
||||
parentApp.use(urlUtils.getApiPath('deprecated'), require('./api/v0.1/app')());
|
||||
parentApp.use(urlUtils.getApiPath('active'), require('./api/v2/content/app')());
|
||||
parentApp.use(urlUtils.getApiPath('active', true), require('./api/v2/admin/app')());
|
||||
parentApp.use(urlUtils.getApiPath({version: 'deprecated', type: 'content'}), require('./api/v0.1/app')());
|
||||
parentApp.use(urlUtils.getApiPath({version: 'active', type: 'content'}), require('./api/v2/content/app')());
|
||||
parentApp.use(urlUtils.getApiPath({version: 'active', type: 'admin'}), require('./api/v2/admin/app')());
|
||||
|
||||
// ADMIN
|
||||
parentApp.use('/ghost', require('./admin')());
|
||||
|
|
Loading…
Add table
Reference in a new issue