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 SNI example to https-proxy plugin docs #1020

Merged
merged 1 commit into from
Jan 25, 2025
Merged
Changes from all commits
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
38 changes: 37 additions & 1 deletion packages/gasket-plugin-https-proxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,41 @@ The `protocol` and `hostname` are only used for logging about the proxy server
and should not be confused with `target.protocol` and `target.host` which
are used for the actual destination server.

### Example SNI Config

While not specifically called out in the [http-proxy] documentation, the
`ssl` settings are what get passed to node's `createServer` method.
As such, you can use `SNICallback` from the [createServer options].

```diff
// gasket.js
export default makeGasket({
httpsProxy: {
protocol: 'https',
hostname: 'my-host.com',
port: 443,
xfwd: true,
ws: true,
target: {
host: 'localhost',
port: 80
},
+ ssl: {
+ SNICallback: (hostname, cb) => {
+ const ctx = tls.createSecureContext({
+ key: fs.readFileSync(`./certs/${hostname}.key`),
+ cert: fs.readFileSync(`./certs/${hostname}.crt`)
+ });
+ cb(null, ctx);
}
}
}
});
```

> The above snippet is for demonstration purposes only.
> You should not be reading your certs from the filesystem for each request.

## Actions

### startProxyServer
Expand All @@ -82,7 +117,7 @@ export default {
hooks: {
httpsProxy: async function (gasket, httpsProxyConfig) {
return {
...devProxyConfig,
...httpsProxyConfig,
hostname: 'local.example.com',
port: 8443
}
Expand All @@ -97,3 +132,4 @@ export default {

[http-proxy]: https://www.npmjs.com/package/http-proxy
[options]: https://www.npmjs.com/package/http-proxy#options
[createServer options]: https://nodejs.org/docs/latest-v22.x/api/tls.html#tlscreateserveroptions-secureconnectionlistener
Loading