Permalink
Browse files

fix(axios): Handle relative baseURL

This also fixes many typos like `//google.com` and `../foo` (`//` is not meaningful for SSR)
  • Loading branch information...
pi0 committed Jun 10, 2017
1 parent ff6a05f commit 19b8453473e205719b2ef81767a1ad6771cf4766
Showing with 6 additions and 3 deletions.
  1. +6 −3 modules/axios/index.js
@@ -2,6 +2,8 @@ const chalk = require('chalk')
const path = require('path')
const { URL } = require('whatwg-url')
const isUrl = url => url.indexOf('http') === 0 || url.indexOf('//') === 0
const port = process.env.PORT || process.env.npm_package_config_nuxt_port || 3000
const host = process.env.HOST || process.env.npm_package_config_nuxt_host || 'localhost'
@@ -25,10 +27,11 @@ module.exports = function nuxtAxios (moduleOptions) {
options.browserBaseURL = process.env.API_URL_BROWSER
}
options.baseURL = new URL(options.baseURL, `http://${host}:${port}`)
if (!options.browserBaseURL) {
const url = new URL(options.baseURL)
const sameHost = url.host === `${host}:${port}`
options.browserBaseURL = sameHost ? url.pathname : options.baseURL
const sameHost = options.baseURL.host === `${host}:${port}`
options.browserBaseURL = sameHost ? options.baseURL.pathname : options.baseURL
}
// Register plugin

0 comments on commit 19b8453

Please sign in to comment.