diff --git a/packages/decap-cms-backend-gitlab/src/implementation.ts b/packages/decap-cms-backend-gitlab/src/implementation.ts index 769257f0bea3..5b1a15a9ef42 100644 --- a/packages/decap-cms-backend-gitlab/src/implementation.ts +++ b/packages/decap-cms-backend-gitlab/src/implementation.ts @@ -158,6 +158,7 @@ export default class GitLab implements Implementation { backend: 'gitlab', repo: this.repo, token: this.token, + apiRoot: this.apiRoot, }); if (defaultBranchName) { this.branch = defaultBranchName; diff --git a/packages/decap-cms-lib-util/src/API.ts b/packages/decap-cms-lib-util/src/API.ts index 277f045d3603..7654a30db025 100644 --- a/packages/decap-cms-lib-util/src/API.ts +++ b/packages/decap-cms-lib-util/src/API.ts @@ -142,6 +142,7 @@ type Backend = 'github' | 'gitlab' | 'bitbucket'; type RequestConfig = Omit & HeaderConfig & { backend: Backend; + apiRoot?: string; params?: ParamObject; }; @@ -199,7 +200,7 @@ export async function apiRequest( const { token, backend, ...props } = config; const options = { cache: 'no-cache', ...props }; const headers = await constructRequestHeaders({ headers: options.headers || {}, token }); - const baseUrl = apiRoots[backend]; + const baseUrl = config.apiRoot ?? apiRoots[backend]; const url = constructUrlWithParams(`${baseUrl}${path}`, options.params); let responseStatus = 500; try { @@ -220,9 +221,10 @@ export async function getDefaultBranchName(configs: { backend: Backend; repo: string; token?: string; + apiRoot?: string; }) { let apiPath; - const { token, backend, repo } = configs; + const { token, backend, repo, apiRoot } = configs; switch (backend) { case 'gitlab': { apiPath = `/projects/${encodeURIComponent(repo)}`; @@ -236,7 +238,7 @@ export async function getDefaultBranchName(configs: { apiPath = `/repos/${repo}`; } } - const repoInfo = await apiRequest(apiPath, { token, backend }); + const repoInfo = await apiRequest(apiPath, { token, backend, apiRoot }); let defaultBranchName; if (backend === 'bitbucket') { const {