From a8ea331afc5c8d2aaee98a30db84297d7e7e0a8e Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Fri, 9 Feb 2018 01:04:47 +0330 Subject: [PATCH] fix: don't mutate env.API_URL This was causing side-effects and invalid proxy config after reloading nuxt.config.js --- lib/module.js | 5 +++-- lib/plugin.template.js | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/module.js b/lib/module.js index 91a83798..b32d3015 100755 --- a/lib/module.js +++ b/lib/module.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( diff --git a/lib/plugin.template.js b/lib/plugin.template.js index a35ca469..f50e8bc0 100755 --- a/lib/plugin.template.js +++ b/lib/plugin.template.js @@ -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!