Skip to content

Commit

Permalink
chore: axios and apiConfig added
Browse files Browse the repository at this point in the history
  • Loading branch information
omrajsharma committed Jun 20, 2024
1 parent 881d558 commit d2472cd
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 0 deletions.
152 changes: 152 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@emotion/styled": "^11.8.1",
"@mui/icons-material": "^5.6.2",
"@mui/material": "^5.6.2",
"axios": "^1.7.2",
"next": "12.1.5",
"react": "18.0.0",
"react-dom": "18.0.0",
Expand Down
36 changes: 36 additions & 0 deletions client/src/utils/apiConfig.ts
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)
}
)

0 comments on commit d2472cd

Please sign in to comment.