Skip to content

Commit

Permalink
docs: add sni example (#1020)
Browse files Browse the repository at this point in the history
  • Loading branch information
agerard-godaddy authored Jan 25, 2025
1 parent 399e1fb commit 040e466
Showing 1 changed file with 37 additions and 1 deletion.
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

0 comments on commit 040e466

Please sign in to comment.