Permalink
Browse files

fix: don't mutate env.API_URL

This was causing side-effects and invalid proxy config after reloading nuxt.config.js
  • Loading branch information...
pi0 committed Feb 8, 2018
1 parent caa7b96 commit a8ea331afc5c8d2aaee98a30db84297d7e7e0a8e
Showing with 5 additions and 4 deletions.
  1. +3 −2 lib/module.js
  2. +2 −2 lib/plugin.template.js
@@ -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 */
@@ -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(
@@ -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!

0 comments on commit a8ea331

Please sign in to comment.