Skip to content

Commit

Permalink
feat: https option (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pooya Parsa committed Feb 4, 2018
1 parent 4d31c1e commit 9ecb547
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ If you are coming from an older release please be sure to read [Migration Guide]
* [Prefix, Host and Port](#prefix-host-and-port)
* [baseURL](#baseurl)
* [browserBaseURL](#browserbaseurl)
* [https](#https)
* [progress](#progress)
* [proxy](#proxy)
* [retry](#retry)
Expand Down Expand Up @@ -306,6 +307,12 @@ Base URL which is used and prepended to make requests in client side.

Environment variable `API_URL_BROWSER` can be used to **override** `browserBaseURL`.

### `https`

* Default: `false`

If set to `true`, `http://` in both `baseURL` and `browserBaseURL` will be changed into `https://`.

### `progress`

* Default: `true`
Expand Down
10 changes: 9 additions & 1 deletion lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ module.exports = function nuxtAxios (_moduleOptions) {
proxyHeaders: true,
proxyHeadersIgnore: ['accept', 'host'],
proxy: false,
retry: false
retry: false,
https: false
},
moduleOptions
)
Expand Down Expand Up @@ -70,6 +71,13 @@ module.exports = function nuxtAxios (_moduleOptions) {
options.retry = {}
}

// Convert http:// to https:// if https option is on
if (options.https === true) {
const https = s => s.replace('http://', 'https://')
options.baseURL = https(options.baseURL)
options.browserBaseURL = https(options.browserBaseURL)
}

// Register plugin
this.addPlugin({
src: path.resolve(__dirname, 'plugin.template.js'),
Expand Down

0 comments on commit 9ecb547

Please sign in to comment.