Skip to content

Fixed Failed Fetch Issue#413

Merged
toshan-luktuke merged 1 commit intoJdeRobot:masterfrom
Sarvesh-Mishra1981:master-CORS_Issue
Mar 1, 2026
Merged

Fixed Failed Fetch Issue#413
toshan-luktuke merged 1 commit intoJdeRobot:masterfrom
Sarvesh-Mishra1981:master-CORS_Issue

Conversation

@Sarvesh-Mishra1981
Copy link
Copy Markdown
Contributor

@Sarvesh-Mishra1981 Sarvesh-Mishra1981 commented Feb 26, 2026

Hello @jmplaza @javizqh sir,

Previously, when the default frontend port was unavailable, the React development server would automatically suggest running on another port (for example, 4001 or 4002). Although the frontend handled this switch correctly, the Django backend was configured to allow requests from only a single localhost origin. As a result, whenever the frontend changed ports, API requests were blocked due to CORS restrictions, causing the Build and Download feature to fail with a TypeError: Failed to fetch.

The issue stemmed from the backend CORS configuration being limited to one specific origin. When the frontend ran on a different port, that new origin was not included in CORS_ALLOWED_ORIGINS, and the backend rejected the requests.

To fix this, I updated the CORS configuration in backend/settings.py to also accept the common fallback ports (:4001 and :4002). With this change, if the default port is occupied and the frontend switches automatically, the backend will still allow the requests without requiring any manual changes to environment variables.

This improvement ensures a smoother development experience and removes unnecessary friction when standard ports are busy.

Here is a short testing video demonstrating that it works correctly on both ports:
https://drive.google.com/file/d/17Ep7gY37FSukfD5EpdHqx03i1m2FZrcN/view?usp=drive_link

@Sarvesh-Mishra1981
Copy link
Copy Markdown
Contributor Author

@jmplaza , I am open for any changes

@toshan-luktuke
Copy link
Copy Markdown
Collaborator

I think this looks good @BkPankaj, thanks for the contribution @Sarvesh-Mishra1981

@toshan-luktuke toshan-luktuke merged commit 74ad7e2 into JdeRobot:master Mar 1, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants