mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-27 04:43:12 +03:00
9c64d7af81
refs https://github.com/TryGhost/Team/issues/1420 - This changeset makes the "/ghost/api" base path for the APIs centralized in one place and reused by dependent modules. There are couple benefits this refactor brings: easy way to spot where the API base path is used (was hard to find it in regexp) and makes it easy to change the hardcoded path to a configurable one in the future (e.g. host all APIs under `domain.tld/custom-path/awesome-apis/posts`) - I hear that scream from the back of your head: "But hey! This introduced coupling to url-utils!". To that my unswer is: "No. This change only makes the coupling explicit, it's been there already and now can be addressed if we need to!". - A neat thing about his change, making the API work on a custom path is one line away, by moving the hardcoded `/ghost/api` to a config ;)
19 lines
574 B
JavaScript
19 lines
574 B
JavaScript
const UrlUtils = require('@tryghost/url-utils');
|
|
const config = require('./config');
|
|
|
|
const BASE_API_PATH = '/ghost/api';
|
|
|
|
const urlUtils = new UrlUtils({
|
|
getSubdir: config.getSubdir,
|
|
getSiteUrl: config.getSiteUrl,
|
|
getAdminUrl: config.getAdminUrl,
|
|
apiVersions: config.get('api:versions'),
|
|
defaultApiVersion: config.get('api:versions:default'),
|
|
slugs: config.get('slugs').protected,
|
|
redirectCacheMaxAge: config.get('caching:301:maxAge'),
|
|
baseApiPath: BASE_API_PATH
|
|
});
|
|
|
|
module.exports = urlUtils;
|
|
module.exports.BASE_API_PATH = BASE_API_PATH;
|