Skip to content

Commit

Permalink
Axios config refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
lanminik authored Jan 20, 2019
1 parent ab1a2f3 commit 764c0b4
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions interceptor.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import axios from "axios";

// Axios defaults
const baseURL = "https://example.com";
axios.defaults.baseURL = baseURL;

// Active http requests
let activeRequests = 0;

/**
* Request interceptor
* Adds default configuration to axios (baseUrl, token, content-type, etc.)
* Adds a default configuration to axios (baseUrl, token, content-type, etc.)
* Counts active http requests
*/
axios.interceptors.request.use(
Expand All @@ -18,9 +22,6 @@ axios.interceptors.request.use(
token = localStorage.getItem("access_token") || null;
}

config.headers["Content-type"] = "application/json";
config.baseURL = "https://example.com";

if (token != null) {
config.headers.Authorization = `Bearer ${token}`;
}
Expand Down

0 comments on commit 764c0b4

Please sign in to comment.