add support for server side http proxy, close #240
This commit is contained in:
parent
fc8a9f4506
commit
ae990fc370
4 changed files with 59 additions and 0 deletions
|
@ -67,3 +67,24 @@ list of strings you can override.
|
||||||
|
|
||||||
> warning "Restart needed"
|
> warning "Restart needed"
|
||||||
> Note that a restart is needed when you change user_locale's content.
|
> Note that a restart is needed when you change user_locale's content.
|
||||||
|
|
||||||
|
### Proxy
|
||||||
|
Proxy outward request from gancio.
|
||||||
|
Look [here](https://www.npmjs.com/package/https-proxy-agent) for options.
|
||||||
|
Note: `hostname` option takes precedence over `host`.
|
||||||
|
|
||||||
|
```json
|
||||||
|
"proxy": {
|
||||||
|
"protocol": "http:",
|
||||||
|
"hostname": "",
|
||||||
|
"host": "127.0.0.1",
|
||||||
|
"port": "8118",
|
||||||
|
"auth": {
|
||||||
|
"username": "user",
|
||||||
|
"password": "password"
|
||||||
|
},
|
||||||
|
"headers": {
|
||||||
|
"X-Proxy-Header": "example"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
26
modules/axios-proxy.js
Normal file
26
modules/axios-proxy.js
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
const HttpsProxyAgent = require("https-proxy-agent"),
|
||||||
|
axios = require("axios"),
|
||||||
|
config = require('../server/config')
|
||||||
|
|
||||||
|
function axiosProxy (_moduleOptions) {
|
||||||
|
|
||||||
|
if (config.proxy && !(!config.proxy.hostname && !config.proxy.host)) {
|
||||||
|
const httpsAgent = new HttpsProxyAgent({
|
||||||
|
protocol: config.proxy.protocol,
|
||||||
|
hostname: config.proxy.hostname,
|
||||||
|
host: config.proxy.host,
|
||||||
|
port: config.proxy.port,
|
||||||
|
auth: config.proxy.auth.username + ':' + config.proxy.auth.password,
|
||||||
|
headers: config.proxy.headers
|
||||||
|
})
|
||||||
|
|
||||||
|
// Use axios as you normally would, but specify httpsAgent in the default configs
|
||||||
|
// https://github.com/nuxt-community/axios-module/pull/428#issuecomment-743313813
|
||||||
|
// Nuxt 2: https://github.com/axios/axios/issues/925#issuecomment-513028175
|
||||||
|
// Nuxt 3: https://github.com/unjs/ofetch#-adding-https-agent
|
||||||
|
axios.defaults.httpsAgent = httpsAgent
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = axiosProxy
|
|
@ -55,6 +55,7 @@ module.exports = {
|
||||||
modules: [
|
modules: [
|
||||||
// Doc: https://axios.nuxtjs.org/usage
|
// Doc: https://axios.nuxtjs.org/usage
|
||||||
'@nuxtjs/i18n',
|
'@nuxtjs/i18n',
|
||||||
|
'~/modules/axios-proxy.js', // Note: import this before @nuxtjs/axios to override defaults of both instances: `$axios` available in context, and `axios` used in controllers
|
||||||
'@nuxtjs/axios',
|
'@nuxtjs/axios',
|
||||||
'@nuxtjs/auth',
|
'@nuxtjs/auth',
|
||||||
'@nuxtjs/sitemap',
|
'@nuxtjs/sitemap',
|
||||||
|
|
|
@ -15,6 +15,17 @@ let config = {
|
||||||
db: {},
|
db: {},
|
||||||
user_locale: path.resolve(process.env.cwd || '', 'user_locale'),
|
user_locale: path.resolve(process.env.cwd || '', 'user_locale'),
|
||||||
upload_path: path.resolve(process.env.cwd || '', 'uploads'),
|
upload_path: path.resolve(process.env.cwd || '', 'uploads'),
|
||||||
|
proxy: {
|
||||||
|
protocol: process.env.GANCIO_PROXY_PROTOCOL || '',
|
||||||
|
hostname: process.env.GANCIO_PROXY_HOSTNAME || '',
|
||||||
|
host: process.env.GANCIO_PROXY_HOST || '',
|
||||||
|
port: process.env.GANCIO_PROXY_PORT || '',
|
||||||
|
auth: {
|
||||||
|
username: process.env.GANCIO_PROXY_USERNAME || '',
|
||||||
|
password: process.env.GANCIO_PROXY_PASSWORD || ''
|
||||||
|
},
|
||||||
|
headers: process.env.GANCIO_PROXY_HEADERS && JSON.parse(process.env.GANCIO_PROXY_HEADERS) || {}
|
||||||
|
},
|
||||||
write (config_path= process.env.config_path || './config.json') {
|
write (config_path= process.env.config_path || './config.json') {
|
||||||
delete config.status
|
delete config.status
|
||||||
return fs.writeFileSync(config_path, JSON.stringify(config, null, 2))
|
return fs.writeFileSync(config_path, JSON.stringify(config, null, 2))
|
||||||
|
|
Loading…
Reference in a new issue