Last active
April 29, 2017 12:58
-
-
Save srph/8b8b8d409a3397d86493 to your computer and use it in GitHub Desktop.
axios: Configure the base path with interceptors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var axios = require('axios'); | |
var join = require('url-join'); | |
// https://github.com/sindresorhus/is-absolute-url/blob/master/index.js#L7 | |
var isAbsoluteURLRegex = /^(?:\w+:)\/\//; | |
axios.interceptors.request.use(function(config) { | |
// Concatenate base path if not an absolute URL | |
if ( !isAbsoluteURLRegex.test(config.url) ) { | |
config.url = join('http://my-api.com', config.url); | |
} | |
return config; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment