mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
parent
48d6e7298a
commit
732f97a074
8 changed files with 9 additions and 16 deletions
|
@ -1,5 +1,3 @@
|
|||
const config = require('../config');
|
||||
module.exports = require('./v0.1');
|
||||
module.exports['v0.1'] = require('./v0.1');
|
||||
module.exports.v2 = require('./v2');
|
||||
module.exports.active = require(`./${config.get('api:versions:active')}`);
|
||||
|
|
|
@ -69,9 +69,6 @@
|
|||
"api": {
|
||||
"versions": {
|
||||
"all": ["v0.1", "v2"],
|
||||
"active": "v2",
|
||||
"stable": "",
|
||||
"deprecated": "v0.1",
|
||||
"v2": {
|
||||
"admin": "v2/admin",
|
||||
"content": "v2/content",
|
||||
|
|
|
@ -44,7 +44,7 @@ function initialiseServices() {
|
|||
scheduling.init({
|
||||
schedulerUrl: config.get('scheduling').schedulerUrl,
|
||||
active: config.get('scheduling').active,
|
||||
apiUrl: urlService.utils.urlFor('api', {version: 'deprecated', versionType: 'content'}, true),
|
||||
apiUrl: urlService.utils.urlFor('api', {version: 'v0.1', versionType: 'content'}, true),
|
||||
internalPath: config.get('paths').internalSchedulingPath,
|
||||
contentPath: config.getContentPath('scheduling')
|
||||
})
|
||||
|
|
|
@ -28,7 +28,7 @@ function getApiPath(options) {
|
|||
*/
|
||||
function getVersionPath(options) {
|
||||
const apiVersions = config.get('api:versions');
|
||||
let requestedVersion = options.version || 'deprecated';
|
||||
let requestedVersion = options.version || 'v0.1';
|
||||
let requestedVersionType = options.type || 'content';
|
||||
let versionData = apiVersions[requestedVersion];
|
||||
if (typeof versionData === 'string') {
|
||||
|
@ -330,7 +330,7 @@ function urlFor(context, data, absolute) {
|
|||
}
|
||||
} else if (context === 'api') {
|
||||
urlPath = getAdminUrl() || getBlogUrl();
|
||||
let apiPath = getApiPath({version: 'deprecated', type: 'content'});
|
||||
let apiPath = getApiPath({version: 'v0.1', 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
|
||||
|
|
|
@ -27,7 +27,7 @@ const crypto = require('crypto'),
|
|||
_ = require('lodash'),
|
||||
url = require('url'),
|
||||
debug = require('ghost-ignition').debug('update-check'),
|
||||
api = require('./api').active,
|
||||
api = require('./api').v2,
|
||||
config = require('./config'),
|
||||
urlService = require('./services/url'),
|
||||
common = require('./lib/common'),
|
||||
|
|
|
@ -26,7 +26,7 @@ function servePublicFile(file, type, maxAge) {
|
|||
|
||||
if (type === 'text/xsl' || type === 'text/plain' || type === 'application/javascript') {
|
||||
buf = buf.toString().replace(blogRegex, urlService.utils.urlFor('home', true).replace(/\/$/, ''));
|
||||
buf = buf.toString().replace(apiRegex, urlService.utils.urlFor('api', {cors: true, version: 'deprecated', versionType: 'content'}, true));
|
||||
buf = buf.toString().replace(apiRegex, urlService.utils.urlFor('api', {cors: true, version: 'v0.1', versionType: 'content'}, true));
|
||||
}
|
||||
content = {
|
||||
headers: {
|
||||
|
|
|
@ -8,7 +8,7 @@ const uuid = require('uuid');
|
|||
const testUtils = require('../utils');
|
||||
const configUtils = require('../utils/configUtils');
|
||||
const packageInfo = require('../../../package');
|
||||
const api = require('../../server/api').active;
|
||||
const api = require('../../server/api').v2;
|
||||
|
||||
const sandbox = sinon.sandbox.create();
|
||||
|
||||
|
|
|
@ -438,15 +438,13 @@ describe('Url', function () {
|
|||
urlService.utils.urlFor('admin', true).should.equal('http://something.com/blog/ghost/');
|
||||
});
|
||||
|
||||
['deprecated', 'active', 'v0.1', 'v2'].forEach((apiVersion) => {
|
||||
['v0.1', 'v2'].forEach((apiVersion) => {
|
||||
function getApiPath(options) {
|
||||
const baseAPIPath = '/ghost/api/';
|
||||
|
||||
switch (options.version) {
|
||||
case 'deprecated':
|
||||
case 'v0.1':
|
||||
return `${baseAPIPath}v0.1/`;
|
||||
case 'active':
|
||||
case 'v2':
|
||||
if (options.versionType === 'admin') {
|
||||
return `${baseAPIPath}v2/admin/`;
|
||||
|
@ -601,7 +599,7 @@ describe('Url', function () {
|
|||
url: 'https://my-ghost-blog.com'
|
||||
});
|
||||
|
||||
urlService.utils.urlFor('api', {cors: true, version: "active", versionType: 'content'}, true).should.eql('https://my-ghost-blog.com/ghost/api/v2/content/');
|
||||
urlService.utils.urlFor('api', {cors: true, version: "v2", versionType: 'content'}, true).should.eql('https://my-ghost-blog.com/ghost/api/v2/content/');
|
||||
});
|
||||
|
||||
it('api: with active version and admin true, blog url is https: should return active admin api path', function () {
|
||||
|
@ -609,7 +607,7 @@ describe('Url', function () {
|
|||
url: 'https://my-ghost-blog.com'
|
||||
});
|
||||
|
||||
urlService.utils.urlFor('api', {cors: true, version: "active", versionType: 'admin'}, true).should.eql('https://my-ghost-blog.com/ghost/api/v2/admin/');
|
||||
urlService.utils.urlFor('api', {cors: true, version: "v2", versionType: 'admin'}, true).should.eql('https://my-ghost-blog.com/ghost/api/v2/admin/');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue