-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
881d558
commit d2472cd
Showing
3 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import axios from 'axios' | ||
|
||
const baseURL = process.env.NEXT_PUBLIC_BASE_URL | ||
|
||
export const axiosInstance = axios.create({ | ||
baseURL: baseURL, | ||
// header will be added later | ||
}) | ||
|
||
// Add a request interceptor | ||
axiosInstance.interceptors.request.use( | ||
function (config) { | ||
// Do something before request is sent | ||
// For example, you can add authorization token here | ||
// config.headers.Authorization = `Bearer ${token}`; | ||
return config | ||
}, | ||
function (error) { | ||
// Do something with request error | ||
return Promise.reject(error) | ||
} | ||
) | ||
|
||
// Add a response interceptor | ||
axiosInstance.interceptors.response.use( | ||
function (response) { | ||
// Any status code that lie within the range of 2xx cause this function to trigger | ||
// Do something with response data | ||
return response | ||
}, | ||
function (error) { | ||
// Any status codes that falls outside the range of 2xx cause this function to trigger | ||
// Do something with response error | ||
return Promise.reject(error) | ||
} | ||
) |