Created
August 22, 2024 18:21
-
-
Save santospatrick/a151588ce51703e41896874ee6b606b3 to your computer and use it in GitHub Desktop.
Axios random delay in local development HTTP calls
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
import axios from 'axios' | |
export const api = axios.create({ | |
baseURL: "http://localhost:3333", | |
withCredentials: true, | |
}) | |
if (env.VITE_ENABLE_API_DELAY) { | |
api.interceptors.request.use(async (config) => { | |
await new Promise((resolve) => | |
setTimeout(resolve, Math.round(Math.random() * 3000)), | |
) | |
return config | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment