Phase 2: scaffold Waiter PWA — React+Vite, PWA manifest, all pages and components
This commit is contained in:
23
waiter_pwa/src/api/client.js
Normal file
23
waiter_pwa/src/api/client.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import axios from 'axios'
|
||||
|
||||
const BASE_URL = import.meta.env.VITE_API_URL || 'http://192.168.1.10:8000'
|
||||
|
||||
const client = axios.create({ baseURL: BASE_URL })
|
||||
|
||||
client.interceptors.request.use(config => {
|
||||
const token = localStorage.getItem('token')
|
||||
if (token) config.headers.Authorization = `Bearer ${token}`
|
||||
return config
|
||||
})
|
||||
|
||||
client.interceptors.response.use(
|
||||
res => res,
|
||||
err => {
|
||||
if (!err.response) {
|
||||
window.dispatchEvent(new Event('backend-offline'))
|
||||
}
|
||||
return Promise.reject(err)
|
||||
}
|
||||
)
|
||||
|
||||
export default client
|
||||
Reference in New Issue
Block a user