mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
refs: https://github.com/TryGhost/Toolbox/issues/229 - our api-key audience handling code is still relying on internal api version config - the regex used is also buggy (it expects 3 parts, which isn't true without versions) and doesn't always match, in which case it can cause the tests to hang - we already had some very similar code in the version-rewrite middleware which is also validates exact values for version and api type - moved this code into a util inside api-version-compatibility-service - using this code, all the tests still pass as is, but when I start to adjust them to cover more cases, none hang (test changes coming in a separate commit)
21 lines
464 B
JavaScript
21 lines
464 B
JavaScript
const pathMatch = require('path-match')();
|
|
|
|
module.exports = (url) => {
|
|
let apiRouteMatcher = '/:version(v2|v3|v4|canary)?/:api(admin|content)/*';
|
|
|
|
if (url.startsWith('/ghost/api')) {
|
|
apiRouteMatcher = `/ghost/api${apiRouteMatcher}`;
|
|
}
|
|
|
|
if (!url.endsWith('/')) {
|
|
url += '/';
|
|
}
|
|
|
|
let {version, api} = pathMatch(apiRouteMatcher)(url);
|
|
|
|
if (version === [null]) {
|
|
version = null;
|
|
}
|
|
|
|
return {version, api};
|
|
};
|