Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add changeOrigin flag for http-proxy and update readme #282

Merged
merged 2 commits into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ new Verifier().verifyProvider(opts).then(function () {
| `timeout` | false | number | The duration in ms we should wait to confirm verification process was successful. Defaults to 30000. |
| `requestFilter` | false | object | An Express middleware handler (See https://expressjs.com/en/guide/writing-middleware.html) to modify requests and responses from the provider. See below for more details. |
| `stateHandlers` | false | object | Provider state handlers. A map of `string` -> `() => Promise`, where each string is the state to setup, and the function is used to configure the state in the Provider. See below for detail. |
| `validateSSL` | false | boolean | Allow self-signed certificates. Defaults to true, if not set. |
| `changeOrigin` | false | boolean | Changes the origin of the host header to the target URL. Defaults to false, if not set. |

</details>

Expand Down Expand Up @@ -341,7 +343,7 @@ Sometimes you may need to add things to the requests that can't be persisted in
For these cases, we have two facilities that should be carefully used during verification:

1. the ability to specify custom headers to be sent during provider verification. The flag to achieve this is `customProviderHeaders`.
1. the ability to modify a request/response and modify the payload. The flag to achieve this is `requestFilter`.
2. the ability to modify a request/response and modify the payload. The flag to achieve this is `requestFilter`.

**Example API with Authorization**

Expand Down
5 changes: 5 additions & 0 deletions src/dsl/verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface VerifierOptions {
format?: "json" | "RspecJunitFormatter"
out?: string
validateSSL?: boolean
changeOrigin?: boolean
}

export class Verifier {
Expand Down Expand Up @@ -156,6 +157,7 @@ export class Verifier {
app.all("/*", (req, res) => {
logger.debug("Proxing", req.path)
proxy.web(req, res, {
changeOrigin: this.config.changeOrigin === false,
mefellows marked this conversation as resolved.
Show resolved Hide resolved
secure: this.config.validateSSL === true,
target: this.config.providerBaseUrl,
})
Expand Down Expand Up @@ -209,6 +211,9 @@ export class Verifier {
if (this.config.validateSSL === undefined) {
this.config.validateSSL = true
}
if (this.config.changeOrigin === undefined) {
this.config.changeOrigin = false
}

if (this.config.logLevel && !isEmpty(this.config.logLevel)) {
serviceFactory.logLevel(this.config.logLevel)
Expand Down