Skip to content

Commit 9ecb547

Browse files
author
Pooya Parsa
committed
feat: https option (#57)
1 parent 4d31c1e commit 9ecb547

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ If you are coming from an older release please be sure to read [Migration Guide]
6363
* [Prefix, Host and Port](#prefix-host-and-port)
6464
* [baseURL](#baseurl)
6565
* [browserBaseURL](#browserbaseurl)
66+
* [https](#https)
6667
* [progress](#progress)
6768
* [proxy](#proxy)
6869
* [retry](#retry)
@@ -306,6 +307,12 @@ Base URL which is used and prepended to make requests in client side.
306307

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

310+
### `https`
311+
312+
* Default: `false`
313+
314+
If set to `true`, `http://` in both `baseURL` and `browserBaseURL` will be changed into `https://`.
315+
309316
### `progress`
310317

311318
* Default: `true`

lib/module.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ module.exports = function nuxtAxios (_moduleOptions) {
4141
proxyHeaders: true,
4242
proxyHeadersIgnore: ['accept', 'host'],
4343
proxy: false,
44-
retry: false
44+
retry: false,
45+
https: false
4546
},
4647
moduleOptions
4748
)
@@ -70,6 +71,13 @@ module.exports = function nuxtAxios (_moduleOptions) {
7071
options.retry = {}
7172
}
7273

74+
// Convert http:// to https:// if https option is on
75+
if (options.https === true) {
76+
const https = s => s.replace('http://', 'https://')
77+
options.baseURL = https(options.baseURL)
78+
options.browserBaseURL = https(options.browserBaseURL)
79+
}
80+
7381
// Register plugin
7482
this.addPlugin({
7583
src: path.resolve(__dirname, 'plugin.template.js'),

0 commit comments

Comments
 (0)