Skip to content
Permalink
Browse files

feat: add function helper `setBaseURL` (#296)

  • Loading branch information
ricardogobbosouza authored and pi0 committed Oct 21, 2019
1 parent af1e86d commit c429d555202620343bc79b70bad3aa61958fb368
Showing with 28 additions and 0 deletions.
  1. +25 −0 docs/helpers.md
  2. +3 −0 lib/plugin.js
@@ -36,6 +36,31 @@ let data = (await $axios.get('...')).data
let data = await $axios.$get('...')
```

### `setBaseURL(baseURL)`

Axios instance has an additional helper to easily change baseURL.

Use this when you need a dynamic runtime url. Otherwise use config and environment variables.

Parameters:

* **baseURL**: Base URL which is used and prepended to make requests in server side.

```js
// Set baseURL (both client and server)
this.$axios.setBaseURL('http://api.example.com')
// Change URL only for client
if (process.client) {
this.$axios.setBaseURL('http://api.example.com')
}
// Change URL only for server
if (process.server) {
this.$axios.setBaseURL('http://api.example.com')
}
```

### `setHeader(name, value, scopes='common')`

Axios instance has a helper to easily set any header.
@@ -3,6 +3,9 @@ import Axios from 'axios'

// Axios.prototype cannot be modified
const axiosExtra = {
setBaseURL (baseURL) {
this.defaults.baseURL = baseURL
},
setHeader (name, value, scopes = 'common') {
for (let scope of Array.isArray(scopes) ? scopes : [ scopes ]) {
if (!value) {

0 comments on commit c429d55

Please sign in to comment.
You can’t perform that action at this time.