-
-
Save danielo515/b4b3a95385786580b6333dc9dc4e8d40 to your computer and use it in GitHub Desktop.
axios: Configure the base path with interceptors
This file contains 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