2022-05-06 07:57:37 +01:00
|
|
|
const pathMatch = require('path-match')();
|
|
|
|
|
|
|
|
module.exports = (url) => {
|
2022-05-10 13:55:19 +01:00
|
|
|
let basePath = 'ghost/api';
|
2022-05-06 07:57:37 +01:00
|
|
|
let apiRouteMatcher = '/:version(v2|v3|v4|canary)?/:api(admin|content)/*';
|
2022-05-10 13:55:19 +01:00
|
|
|
let urlToMatch = url;
|
2022-05-06 07:57:37 +01:00
|
|
|
|
2022-05-10 13:55:19 +01:00
|
|
|
if (url.includes(basePath)) {
|
|
|
|
urlToMatch = url.split(basePath)[1];
|
2022-05-06 07:57:37 +01:00
|
|
|
}
|
|
|
|
|
2022-05-10 13:55:19 +01:00
|
|
|
if (!urlToMatch.endsWith('/')) {
|
|
|
|
urlToMatch += '/';
|
2022-05-06 07:57:37 +01:00
|
|
|
}
|
|
|
|
|
2022-05-10 13:55:19 +01:00
|
|
|
let {version, api} = pathMatch(apiRouteMatcher)(urlToMatch);
|
2022-05-06 07:57:37 +01:00
|
|
|
|
|
|
|
if (version === [null]) {
|
|
|
|
version = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {version, api};
|
|
|
|
};
|