Skip to content

Commit

Permalink
feat: support baseUrl and browserBaseUrl to handle casing typos
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 1, 2021
1 parent a1a1894 commit 8904847
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ function axiosModule (_moduleOptions) {
patch: {}
}

// Support baseUrl alternative
if (moduleOptions.baseUrl) {
moduleOptions.baseURL = moduleOptions.baseUrl
delete moduleOptions.baseUrl
}
if (moduleOptions.browserBaseUrl) {
moduleOptions.browserBaseURL = moduleOptions.browserBaseUrl
delete moduleOptions.browserBaseUrl
}

// Apply defaults
const options = defu(moduleOptions, {
baseURL: `http://${defaultHost}:${defaultPort}${prefix}`,
Expand Down
4 changes: 2 additions & 2 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ export default (ctx, inject) => {
const runtimeConfig = ctx.$config && ctx.$config.axios || {}
// baseURL
const baseURL = process.browser
? (runtimeConfig.browserBaseURL || runtimeConfig.baseURL || '<%= options.browserBaseURL || '' %>')
: (runtimeConfig.baseURL || process.env._AXIOS_BASE_URL_ || '<%= options.baseURL || '' %>')
? (runtimeConfig.browserBaseURL || runtimeConfig.browserBaseUrl || runtimeConfig.baseURL || runtimeConfig.baseUrl || '<%= options.browserBaseURL || '' %>')
: (runtimeConfig.baseURL || runtimeConfig.baseUrl || process.env._AXIOS_BASE_URL_ || '<%= options.baseURL || '' %>')

This comment has been minimized.

Copy link
@minicatsCB

minicatsCB Feb 4, 2021

Why is runtimeConfig.baseURL repeated twice?

This comment has been minimized.

Copy link
@amjmhs

amjmhs Feb 4, 2021

@minicatsCB look at the large and lower case .. it's different: URL vs Url

This comment has been minimized.

Copy link
@pi0

pi0 Feb 4, 2021

Author Member

Note Url vs URL :) (and there is an inline condition with process.browser

This comment has been minimized.

Copy link
@minicatsCB

minicatsCB Feb 5, 2021

Didn't notice! Thanks both!


// Create fresh objects for all default header scopes
// Axios creates only one which is shared across SSR requests!
Expand Down

0 comments on commit 8904847

Please sign in to comment.