-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(h5p-server): added forward proxy support (#1414)
- Loading branch information
Showing
12 changed files
with
161 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Forward proxy support | ||
|
||
@lumieducation/h5p-server has to make outgoing HTTPS requests to contact the H5P | ||
Hub. If your network requires the use of a forward proxy to reach the Internet, | ||
you must configure @lumieducation/h5p-server to use it for the HTTPS requests. | ||
|
||
There are two ways of enabling the proxy: | ||
|
||
1. Set the `proxy` property in IH5PConfig like this: | ||
```json | ||
{ | ||
"proxy": { | ||
"host": "10.1.2.3", | ||
"port": 8080, | ||
"protocol": "https" // can also be left out or set to "http" if your proxy can't be accessed with https | ||
} | ||
} | ||
``` | ||
|
||
2. Set the HTTPS_PROXY environment variable like this: | ||
|
||
``HTTPS_PROXY=http://10.1.2.3:8080`` | ||
or | ||
``HTTPS_PROXY=https://10.1.2.3:8080`` | ||
|
||
(depending on whether your proxy can be accessed with https). |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import axios, { AxiosInstance } from 'axios'; | ||
// We need to use https-proxy-agent as the default Axios proxy functionality | ||
// doesn't work with https. | ||
import HttpsProxyAgent from 'https-proxy-agent'; | ||
import { IH5PConfig } from '../types'; | ||
|
||
/** | ||
* Creates an Axios instance that supports corporate HTTPS proxies. | ||
* The proxy can either be configured in the config's proxy property or by | ||
* setting the environment variable HTTPS_PROXY. | ||
* @param config the H5P config object | ||
* @returns the AxiosInstance | ||
*/ | ||
const getClient = (config: IH5PConfig): AxiosInstance => { | ||
let proxyAgent; | ||
|
||
if (config.proxy) { | ||
proxyAgent = HttpsProxyAgent({ | ||
host: config.proxy.host, | ||
port: config.proxy.port, | ||
protocol: config.proxy.protocol === 'https' ? 'https:' : undefined | ||
}); | ||
} else if (process.env.HTTPS_PROXY) { | ||
proxyAgent = HttpsProxyAgent(process.env.HTTPS_PROXY); | ||
} | ||
|
||
return axios.create({ | ||
proxy: proxyAgent ? false : undefined, | ||
httpsAgent: proxyAgent | ||
}); | ||
}; | ||
|
||
export default getClient; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters