Skip to content

Commit

Permalink
feat(proxy): add proxy and raw-proxy config
Browse files Browse the repository at this point in the history
  • Loading branch information
Benedikt Rötsch authored and axe312ger committed Aug 28, 2018
1 parent d778f41 commit 551058b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@
- [`transformEntries(config)`](#transformentriesconfig)
- [`transformEntries` Example](#transformentries-example)
- [`deriveLinkedEntries(config)`](#derivelinkedentriesconfig)
- [`deriveLinkedEntries` Example](#derivelinkedentries-example)
- [`deriveLinkedEntries(config)` Example](#derivelinkedentriesconfig-example)
- [`context`](#context)
- [`makeRequest(config)`](#makerequestconfig)
- [`spaceId` : `string`](#spaceid--string)
- [`accessToken` : `string`](#accesstoken--string)
- [Content type](#content-type)
- [`createField(id[, opts])` : [Field](#field)](#createfieldid-opts--fieldfield)
- [`editField(id[, opts])` : [Field](#field)](#editfieldid-opts--fieldfield)
Expand All @@ -75,6 +79,7 @@
- [Field](#field)
- [Validation errors](#validation-errors)
- [Example migrations](#example-migrations)
- [Troubleshooting](#troubleshooting)
- [Reach out to us](#reach-out-to-us)
- [You have questions about how to use this library?](#you-have-questions-about-how-to-use-this-library)
- [You found a bug or want to propose a feature?](#you-found-a-bug-or-want-to-propose-a-feature)
Expand Down Expand Up @@ -468,6 +473,18 @@ migrations()
```
## Troubleshooting
* Unable to connect to Contentful through your Proxy? Try to set the `rawProxy` option to `true`.
```javascript
runMigration({
proxy: 'https://cat:[email protected]:1234',
rawProxy: true,
...
})
```
## Reach out to us
### You have questions about how to use this library?
Expand Down
15 changes: 9 additions & 6 deletions src/bin/lib/contentful-client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ import { createClient as _createClient } from 'contentful-management'
let createClient = _createClient

function createManagementClient (params) {
const proxyConfig = loadProxyFromEnv(process.env)
const { httpsAgent } = agentFromProxy(proxyConfig)
if (!params.application) {
throw new Error('Please specify the application name that uses this client instance')
}

const config = Object.assign({ httpsAgent }, params)
params.proxy = params.proxy || loadProxyFromEnv(process.env)

if (!config.application) {
throw new Error('Please specify the application name that uses this client instance')
if (!params.rawProxy) {
const { httpsAgent } = agentFromProxy(params.proxy)
params.httpsAgent = httpsAgent
delete params.proxy
}

return createClient(config)
return createClient(params)
}

export {
Expand Down
9 changes: 9 additions & 0 deletions src/bin/usage-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ export default yargs
alias: 'a',
describe: 'The access token to use\nThis takes precedence over environment variables or .contentfulrc'
})
.option('proxy', {
describe: 'Proxy configuration in HTTP auth format: [http|https]://host:port or [http|https]://user:password@host:port',
type: 'string'
})
.option('raw-proxy', {
describe: 'Pass proxy config to Axios instead of creating a custom httpsAgent',
type: 'boolean',
default: false
})
.option('yes', {
alias: 'y',
boolean: true,
Expand Down

0 comments on commit 551058b

Please sign in to comment.