Skip to content

Instantly share code, notes, and snippets.

@acyuta
Last active October 10, 2019 08:14
Show Gist options
  • Save acyuta/04a9a2e4082eac68ab3ccce0eb04a526 to your computer and use it in GitHub Desktop.
Save acyuta/04a9a2e4082eac68ab3ccce0eb04a526 to your computer and use it in GitHub Desktop.
AxiosBuildExample.js
import axios from "axios";
import AuthService from "./service/AuthService";
const headers = {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Credentials": "true"
};
const HTTP = new axios.create({
responseType: "json",
withCredentials: false,
baseURL: process.env.VUE_APP_ROOT_API || "http://localhost",
timeout: 5000,
headers: {
post: headers
}
});
HTTP.interceptors.request.use(
function(config) {
const token = AuthService.getToken();
if (token) config.headers.Authorization = `Bearer ${token}`;
return config;
},
function(error) {
return Promise.reject(error);
}
);
export default HTTP;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment