Skip to content

Commit

Permalink
fix: don't mutate env.API_URL
Browse files Browse the repository at this point in the history
This was causing side-effects and invalid proxy config after reloading nuxt.config.js
  • Loading branch information
Pooya Parsa committed Feb 8, 2018
1 parent caa7b96 commit a8ea331
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ module.exports = function nuxtAxios (_moduleOptions) {
/* istanbul ignore if */
if (process.env.API_URL) {
options.baseURL = process.env.API_URL
} else {
process.env.API_URL = options.baseURL
}

/* istanbul ignore if */
Expand Down Expand Up @@ -93,6 +91,9 @@ module.exports = function nuxtAxios (_moduleOptions) {
])
}

// Set _AXIOS_BASE_URL_ for dynamic SSR baseURL
process.env._AXIOS_BASE_URL_ = options.baseURL

/* eslint-disable no-console */
debug(
`BaseURL: ${chalk.green(options.baseURL)} (Browser: ${chalk.green(
Expand Down
4 changes: 2 additions & 2 deletions lib/plugin.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ export default (ctx, inject) => {
const axiosOptions = {
// baseURL
baseURL : process.browser
? (process.env.API_URL_BROWSER || '<%= options.browserBaseURL %>')
: (process.env.API_URL || '<%= options.baseURL %>'),
? '<%= options.browserBaseURL %>'
: (process.env._AXIOS_BASE_URL_ || '<%= options.baseURL %>'),

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

0 comments on commit a8ea331

Please sign in to comment.