Skip to content

Instantly share code, notes, and snippets.

@santospatrick
Created August 22, 2024 18:21
Show Gist options
  • Save santospatrick/a151588ce51703e41896874ee6b606b3 to your computer and use it in GitHub Desktop.
Save santospatrick/a151588ce51703e41896874ee6b606b3 to your computer and use it in GitHub Desktop.
Axios random delay in local development HTTP calls
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