mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Fixed legacyApiPathMatch not working with subdirs
- The recently refactored path matching code forgot to take into account that originalUrl can include the subdir - Added more permutations to tests and ensured that all tests pass - This means we don't have to worry about what sort of path we pass to the function, it'll figure out the version and api info
This commit is contained in:
parent
b7b4f8d1d1
commit
b911c66bb6
2 changed files with 25 additions and 5 deletions
|
@ -1,17 +1,19 @@
|
|||
const pathMatch = require('path-match')();
|
||||
|
||||
module.exports = (url) => {
|
||||
let basePath = 'ghost/api';
|
||||
let apiRouteMatcher = '/:version(v2|v3|v4|canary)?/:api(admin|content)/*';
|
||||
let urlToMatch = url;
|
||||
|
||||
if (url.startsWith('/ghost/api')) {
|
||||
apiRouteMatcher = `/ghost/api${apiRouteMatcher}`;
|
||||
if (url.includes(basePath)) {
|
||||
urlToMatch = url.split(basePath)[1];
|
||||
}
|
||||
|
||||
if (!url.endsWith('/')) {
|
||||
url += '/';
|
||||
if (!urlToMatch.endsWith('/')) {
|
||||
urlToMatch += '/';
|
||||
}
|
||||
|
||||
let {version, api} = pathMatch(apiRouteMatcher)(url);
|
||||
let {version, api} = pathMatch(apiRouteMatcher)(urlToMatch);
|
||||
|
||||
if (version === [null]) {
|
||||
version = null;
|
||||
|
|
|
@ -5,16 +5,22 @@ const legacyApiPathMatch = require('../../../../../core/server/services/api-vers
|
|||
describe('Legacy Path Match', function () {
|
||||
it('returns null, admin for all supported permutations', function () {
|
||||
const permutations = [
|
||||
'/subdir/ghost/api/admin/',
|
||||
'/ghost/api/admin/',
|
||||
'/admin/',
|
||||
'/subdir/ghost/api/admin',
|
||||
'/ghost/api/admin',
|
||||
'/admin',
|
||||
'/subdir/ghost/api/admin/session/',
|
||||
'/ghost/api/admin/session/',
|
||||
'/admin/session/',
|
||||
'/subdir/ghost/api/admin/session',
|
||||
'/ghost/api/admin/session',
|
||||
'/admin/session',
|
||||
'/subdir/ghost/api/admin/session/something/',
|
||||
'/ghost/api/admin/session/something/',
|
||||
'/admin/session/something/',
|
||||
'/subdir/ghost/api/admin/session/something',
|
||||
'/ghost/api/admin/session/something',
|
||||
'/admin/session/something'
|
||||
];
|
||||
|
@ -26,16 +32,22 @@ describe('Legacy Path Match', function () {
|
|||
|
||||
it('returns canary, admin for all supported permutations', function () {
|
||||
const permutations = [
|
||||
'/subdir/ghost/api/canary/admin/',
|
||||
'/ghost/api/canary/admin/',
|
||||
'/canary/admin/',
|
||||
'/subdir/ghost/api/canary/admin',
|
||||
'/ghost/api/canary/admin',
|
||||
'/canary/admin',
|
||||
'/subdir/ghost/api/canary/admin/session/',
|
||||
'/ghost/api/canary/admin/session/',
|
||||
'/canary/admin/session/',
|
||||
'/subdir/ghost/api/canary/admin/session',
|
||||
'/ghost/api/canary/admin/session',
|
||||
'/canary/admin/session',
|
||||
'/subdir/ghost/api/canary/admin/session/something/',
|
||||
'/ghost/api/canary/admin/session/something/',
|
||||
'/canary/admin/session/something/',
|
||||
'/subdir/ghost/api/canary/admin/session/something',
|
||||
'/ghost/api/canary/admin/session/something',
|
||||
'/canary/admin/session/something'
|
||||
];
|
||||
|
@ -47,16 +59,22 @@ describe('Legacy Path Match', function () {
|
|||
|
||||
it('returns v4, admin for all permutations', function () {
|
||||
const permutations = [
|
||||
'/subdir/ghost/api/v4/admin/',
|
||||
'/ghost/api/v4/admin/',
|
||||
'/v4/admin/',
|
||||
'/subdir/ghost/api/v4/admin',
|
||||
'/ghost/api/v4/admin',
|
||||
'/v4/admin',
|
||||
'/subdir/ghost/api/v4/admin/session/',
|
||||
'/ghost/api/v4/admin/session/',
|
||||
'/v4/admin/session/',
|
||||
'/subdir/ghost/api/v4/admin/session',
|
||||
'/ghost/api/v4/admin/session',
|
||||
'/v4/admin/session',
|
||||
'/subdir/ghost/api/v4/admin/session/something/',
|
||||
'/ghost/api/v4/admin/session/something/',
|
||||
'/v4/admin/session/something/',
|
||||
'/subdir/ghost/api/v4/admin/session/something',
|
||||
'/ghost/api/v4/admin/session/something',
|
||||
'/v4/admin/session/something'
|
||||
];
|
||||
|
|
Loading…
Add table
Reference in a new issue