From 4acb81ccb2421f969167d1f6b6c3ad6e11dfe076 Mon Sep 17 00:00:00 2001 From: Tyler Collins Date: Tue, 6 Feb 2024 14:50:33 -0700 Subject: [PATCH] feat: allow overriding the default API host --- src/bin/cli.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/bin/cli.ts b/src/bin/cli.ts index 63964fbf..c843802a 100644 --- a/src/bin/cli.ts +++ b/src/bin/cli.ts @@ -56,7 +56,7 @@ const makeTerminatingFunction = export const createMakeRequest = ( client: PlainClientAPI, - { spaceId, environmentId, limit = 10 } + { spaceId, environmentId, limit = 10, host = 'api.contentful.com' } ) => { const throttle = pThrottle({ limit, @@ -66,7 +66,7 @@ export const createMakeRequest = ( const makeBaseUrl = (url: string) => { const parts = [ - 'https://api.contentful.com', + `https://${host}`, 'spaces', spaceId, 'environments', @@ -114,12 +114,15 @@ const createRun = ({ shouldThrow }) => }, getConfig(argv) ) + // allow users to override the default host via the contentful-cli + argv.host && Object.assign(clientConfig, { host: argv.host }) const client = createManagementClient(clientConfig) const makeRequest = createMakeRequest(client, { spaceId: clientConfig.spaceId, environmentId: clientConfig.environmentId, - limit: argv.requestLimit + limit: argv.requestLimit, + host: clientConfig.host }) const migrationParser = createMigrationParser(makeRequest, clientConfig)