0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00
ghost/core/server/services/api-version-compatibility/legacy-api-path-match.js

24 lines
524 B
JavaScript
Raw Normal View History

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.includes(basePath)) {
urlToMatch = url.split(basePath)[1];
}
if (!urlToMatch.endsWith('/')) {
urlToMatch += '/';
}
let {version, api} = pathMatch(apiRouteMatcher)(urlToMatch);
if (version === [null]) {
version = null;
}
return {version, api};
};