Spaces:
Sleeping
Sleeping
Download src/main.jsx from Shivam4096/Carpool: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/spaces/Shivam4096/Carpool/resolve/main/src/main.jsx
- Command line
-
hf download hf://spaces/Shivam4096/Carpool/src/main.jsx
-
curl -L -o main.jsx https://huggingface.co/spaces/Shivam4096/Carpool/resolve/main/src/main.jsx
1.37 kB
| import { StrictMode } from 'react' | |
| import { createRoot } from 'react-dom/client' | |
| import './index.css' | |
| import App from './App.jsx' | |
| const originalFetch = window.fetch; | |
| window.fetch = async (...args) => { | |
| let [resource, config] = args; | |
| if (typeof resource === 'string' && resource.startsWith('/api')) { | |
| const token = localStorage.getItem('token'); | |
| if (token) { | |
| config = config || {}; | |
| config.headers = { | |
| ...config.headers, | |
| 'Authorization': `Bearer ${token}` | |
| }; | |
| args[1] = config; | |
| } | |
| } | |
| const response = await originalFetch(...args); | |
| if (response.status === 401) { | |
| localStorage.removeItem('token'); | |
| localStorage.removeItem('carpool_session'); | |
| window.location.reload(); | |
| } else if (response.headers.has('X-New-Token')) { | |
| const newToken = response.headers.get('X-New-Token'); | |
| if (newToken) { | |
| localStorage.setItem('token', newToken); | |
| } | |
| } | |
| return response; | |
| }; | |
| createRoot(document.getElementById('root')).render( | |
| <StrictMode> | |
| <App /> | |
| </StrictMode>, | |
| ) | |
| if ('serviceWorker' in navigator) { | |
| window.addEventListener('load', () => { | |
| navigator.serviceWorker.register('/sw.js').then(registration => { | |
| console.log('SW registered: ', registration); | |
| }).catch(registrationError => { | |
| console.log('SW registration failed: ', registrationError); | |
| }); | |
| }); | |
| } | |