Overview
Poway Auto integrates with a backend API hosted atautonomous.stu.nighthawkcodingsociety.com for user authentication, route planning, location verification, and data storage.
API Configuration
Base Configuration
The API configuration is centralized inassets/js/api/config.js (config.js:1-61).
- Development:
localhost:8888or127.0.0.1:8888 - Production:
autonomous.stu.nighthawkcodingsociety.com
Default Fetch Options
mode: 'cors'- Enables Cross-Origin Resource Sharingcredentials: 'include'- Sends cookies with requests for authenticationX-Origin: 'client'- Custom header to identify frontend requests
CORS Setup
Frontend Configuration
All API requests include CORS headers to enable cross-origin communication:Backend Requirements
The backend must respond with appropriate CORS headers:Authentication
Login Flow
The login function inconfig.js (config.js:29-60) handles user authentication:
Session Management
The base layout (base.html:109-144) checks authentication status on page load:- On page load, fetch current user from
/api/user - If authenticated, display user name and link to profile
- If not authenticated, show “Sign In” button
- Session maintained via cookies (credentials: ‘include’)
API Endpoints
User Authentication
Get Current User:Route Planning
Fromnavigation/findBestRoute/map.js (map.js:1-88):
Location Verification
Fromnavigation/verify.html (verify.html:80-147):
Fetch Patterns
Basic GET Request
POST Request
Error Handling
Route Visualization Example
Frommap.js (map.js:21-73):
Testing APIs
Local Development
-
Start backend server:
-
Start frontend:
-
Test endpoints:
Production Testing
Best Practices
1. Always Import from Config
2. Handle Errors Gracefully
3. Use Credentials for Auth
4. Include CORS Headers
Troubleshooting
CORS Errors
Error:Access to fetch at '...' from origin '...' has been blocked by CORS policy
Solution:
- Verify backend CORS headers include your origin
- Check
credentials: 'include'is set - Ensure backend allows credentials
Authentication Issues
Error:Failed to fetch current user
Solution:
- Clear cookies and log in again
- Check network tab for 401/403 responses
- Verify session cookie is being sent
Network Errors
Error:Possible CORS or Service Down error
Solution:
- Check backend server is running
- Verify URL configuration
- Test endpoint with curl
Next Steps
Configuration
Learn about environment and deployment configuration
Project Structure
Review the project file organization