React Proxy | Easiest Fix to CORS Errors

  Рет қаралды 77,638

Sam Meech-Ward

Sam Meech-Ward

Күн бұрын

Proxying API Requests in Development using Vite, Parcel, or Create React App. If your plan is to host your react app from the same origin as your web server, then this is super helpful. Conveniently, this also avoids CORS issues. I'll also show you how to deploy your react app using your express server and railway.
Check out my entire react series: • Everything you need to...
Chapters:
0:00​ Intro
2:56 CORS
3:38 Deploying a React App
7:04 What is React Proxy
8:10 Adding a Proxy
11:14 Building the app for production
13:10 Deploying the app into production
15:13 Summary
🔗The Docs
developer.mozilla.org/en-US/d...
create-react-app.dev/docs/pro...
vitejs.dev/config/server-opti...
parceljs.org/features/develop...
🔗Moar Links
My Website: sammeechward.com
Instagram: / meech_ward
Twitter: / meech_ward
Github: github.com/orgs/Sam-Meech-Ward

Пікірлер: 131
@toxy6355
@toxy6355 Жыл бұрын
sir, 4 hour,its 8:25AM, i was trying to solve this from around 3:30AM. you cant imagine how happy i am right now to find those 4 line of code in ur first 10 sec of video...... i love you man even turned on bell icon cz u saved my project, i was about to delete it
@amouzande9102
@amouzande9102 2 ай бұрын
it took me two days
@---qp8bs
@---qp8bs Жыл бұрын
This entire list of react focussed videos is great, It is obvious you spent a huge amount of energy on taking us along on the learning curve- just compare the first couple of videos to this, it's a great expansion building on the previous knowledge! This video really blew me away with the quick deployment on railway, that's awesome. Also loving the quick snippet at the start showing the main point!
@niranjans.r1930
@niranjans.r1930 Ай бұрын
Unlike every other youtubers who says bunch of nonsense and non related things before giving the actual information for which we came for, You gave the most important information in the first 10 seconds and proceeded to explain it later. You have our respect.
@krishangsharma2185
@krishangsharma2185 4 ай бұрын
I was so stressed out about the whole CORS issue, and this, this is just gold. Straight and to the point explanation! Really appreciate the work!!!
@siddhantsrivastav8591
@siddhantsrivastav8591 Жыл бұрын
Really awesome video. Telling the solution at start and then it's upto the user to say. Love it man! Hope to see more youtubers be this thoughtful
@tiktaktictac
@tiktaktictac Жыл бұрын
This clears up a lot for me man. This is the first time I try to make a fullstack app and all these deployment issues are confusing af. Thumbs up for you 👍
@avalanche-arabic
@avalanche-arabic Жыл бұрын
Thank you so much, after a week of search i got my issue fixed and finally the data renders on my frontend up! Keep up the great work! Thank again!
@amouzande9102
@amouzande9102 2 ай бұрын
Thank you so much for this tutorial, I've searched lots of videos and site but none of them specified exactly how to solve it in vite. really appreciate it Sam
@jaitjacob
@jaitjacob 4 ай бұрын
you make videos of things I've wondered about at some point during my learning process, so good! this cors issue was something I fixed using an extension without really paying attentions to the whys and how's
@knecks7374
@knecks7374 8 ай бұрын
bro after 2 and a half hours of struggling around , i had lost my hope. and the i decided to watch this full video as my last tether to sanity. and that stupid failed to fetch error is finally gone. thank you dude. god bless you.
@juanguerrero0941
@juanguerrero0941 Жыл бұрын
I needed a solution as fast as possible, I looked a lot of videos that didn't help me, but this one in the first 30 seconds gave me the answer, thank you
@itchybakerzz5101
@itchybakerzz5101 Жыл бұрын
I've been looking for a solution about the proxy in vite-react for days, then this video solved it within 20 seconds. Thanks a lot!
@harshitprasad1064
@harshitprasad1064 Жыл бұрын
God bless you man!!! Thank you very much for sharing what I was looking for in the first 10 seconds of the video instead of scattering it throughout the video... ❤
@mrmaahi4945
@mrmaahi4945 Ай бұрын
I never thought that I can solve my intital (proxy setup) and final (deployment) problems by just watching one video. Spent all day trying different way to deploy my project but lost functionality after deployment. Finally deployed using the process in the video and everything is working sooo fine and it's soo easy. I can't thank you more, u really saved my day here and explanation is on point that made me think like, "what the hell, I understand everything this guy saying" . THANK YOU SO MUCH
@explorelifewithleo
@explorelifewithleo Жыл бұрын
This video clears all my doubts about proxy server. amazing content!!
@oyivosamuel7185
@oyivosamuel7185 Жыл бұрын
I dont really know u and this is my first time of watching ur video but ur video just saved me after 4 days of trying to connect my vite React project with my node js without using cors.......U are a life saver for that am subscribing......thanks again
@CoFloCipher
@CoFloCipher Жыл бұрын
Just wanted to say this helped me in a bind. Thank you!
@4xsjb
@4xsjb Ай бұрын
What a legend , i've been stuck with this for 3 days . it almost seemed impossible to solve then this video showed up when i was just scrolling 😄
@danielcinspace1
@danielcinspace1 Жыл бұрын
The first video I have ever commented on. CORS was driving me nuts. Thank you!
@MatthewMcGuff
@MatthewMcGuff Жыл бұрын
I really like this pattern for building full stack react and node applications. Thanks for the video.
@number5322
@number5322 Жыл бұрын
I spent a whole night trying to circumvent those cors issues. Thank you very much. Now I'll go get some sleep
@sagarchawla4926
@sagarchawla4926 Жыл бұрын
Amazing dude, i was stuck for a whole day figuring out whats wrong.
@ashharSartaj
@ashharSartaj Жыл бұрын
Can't thank you enough brother. After almost 4 hours of frustration, got the appropriate solution. Also, CORS package wasn't fulfilling the purpose, as suggested by other channels.
@74LS_NE555
@74LS_NE555 Жыл бұрын
thank you for getting to the point from the start [subbed]
@user-qe3fs4ul9y
@user-qe3fs4ul9y 3 ай бұрын
Thank you so much , you can’t imagine how grateful I am for this clearly instructed solution,I’ve been stuck on this CORS issue for 3 days and went through a lot of solutions and videos but yours is what worked best for me 🙏 thank you again
@ankush1228
@ankush1228 11 ай бұрын
i literally spent 2 days on cors and hosting but you made it in 15 min thanks man🥺🥺🥺
@chrisdan81
@chrisdan81 5 ай бұрын
thank you for this... I have been searching for this for 4 hours ...
@rogut8
@rogut8 Жыл бұрын
Wow, that was fast mate. Thank you Sir :)
@mobile_genshin
@mobile_genshin Ай бұрын
omg this is amazing XD immediately subscribed!
@user-hl1ve7wy7p
@user-hl1ve7wy7p 5 ай бұрын
Dude, this vid saved my butt.... spent ages trying to solve a proxy issue... Sub'd!
@aliyazdan6282
@aliyazdan6282 3 ай бұрын
wow it was such a amazing video it got my lot of doubts cleared
@nikolaradulovic9145
@nikolaradulovic9145 Жыл бұрын
Valuable content, thanks for sharing knowledge!
@teminoah2960
@teminoah2960 Жыл бұрын
thanks Mr Sam , this absolutely helpful .
@111ramico
@111ramico 3 ай бұрын
Thank you it was delighted 🙂
@vlogs627
@vlogs627 Жыл бұрын
Thanks. It saved my 4 hours of headache.
@akashddeepchitransh4537
@akashddeepchitransh4537 24 күн бұрын
Incredible video learned a lot
@muhamadsarhad6566
@muhamadsarhad6566 5 ай бұрын
just WOW! man this was amazing.
@abhishekvishal354
@abhishekvishal354 10 ай бұрын
Thank u man so much .... This vid was a blessing
@c1ach027
@c1ach027 Жыл бұрын
Thanks you ^^,I find this pbm with my Java Spring api and Vuejs, after your tutorial it's work. Your the best ^^
@vinodpatil7314
@vinodpatil7314 2 ай бұрын
sir from past 2 days i spent all midnight just chatgping the proxy thing and today just at 0:13 i got the solution thank you so much
@FunkyLPify
@FunkyLPify Жыл бұрын
Thanks very much for the video! Got a bit confused why some other tutorials like uploading an image to S3 didn't work for me with the way you did it, but it was because of the missing proxy haha
@javiergarciafillol4454
@javiergarciafillol4454 Жыл бұрын
Grath, a simply solution for the express & proxy develop
@edwardespinoza1729
@edwardespinoza1729 5 ай бұрын
Awesome video!
@triviachanel
@triviachanel Жыл бұрын
Thanks man, you save my life.
@kishoreandra
@kishoreandra Жыл бұрын
Waoh thanks for the video Sam 🙌 subscribed 😉
@AnsonBenny
@AnsonBenny Жыл бұрын
Tnks bro its working very well, keep going👍
@jaisikadhiman9791
@jaisikadhiman9791 28 күн бұрын
Thanku , after wasted of 2 hours i found the solution of this problem thanku😊
@zihuatanejo7741
@zihuatanejo7741 Жыл бұрын
Thanks a lot, great video :)
@crypto1886
@crypto1886 2 ай бұрын
Thank you, you have recived my sub and like
@scey
@scey 5 ай бұрын
thank you so much! perfect!
@Geekoo
@Geekoo 4 ай бұрын
Wow I can't ask more than this
@user-fy2hp
@user-fy2hp 9 ай бұрын
Thanks that's a great helpful information
@toluwanimiala4729
@toluwanimiala4729 Ай бұрын
great vid 🤌
@mehrosenasir9974
@mehrosenasir9974 10 ай бұрын
Thank you so much from Pakistan!!
@adrn_en
@adrn_en 8 ай бұрын
Thankyou so much!
@thesoftwareengineersjourney
@thesoftwareengineersjourney Жыл бұрын
Thanks I was able to fix a problem with this
@chinwubachukwudi4483
@chinwubachukwudi4483 Жыл бұрын
Thank you so much mate
@StefanoMercadante
@StefanoMercadante 14 күн бұрын
thank you thank you very much!!!!!
@fabianvieri1907
@fabianvieri1907 Жыл бұрын
Great vids, one thing is there a way to automate the build process?
@Lunolux
@Lunolux Жыл бұрын
great video, thx
@yoslandymesa5560
@yoslandymesa5560 Жыл бұрын
Hi Sir. The tutorial is great, but I got catch for the plugin that helps you to complete code, I think you call it Copilot, but I see so many copilot on VS code. Could you be specific which one are you using?
@KCODivyanshuKatyan
@KCODivyanshuKatyan 3 ай бұрын
which extensions are you using for auto complete? nice explaination btw.
@danielgajewski
@danielgajewski Жыл бұрын
Thank you bro!
@CuriousAnonDev
@CuriousAnonDev Жыл бұрын
Thank you Sam :)
@suyogsinnarkar3614
@suyogsinnarkar3614 7 ай бұрын
thank you bro
@modeocheng2190
@modeocheng2190 8 ай бұрын
love it!
@MelakeselamMengistu
@MelakeselamMengistu Жыл бұрын
Thank you for such a clear explanation on CORS and how to resolve related errors. Im facing slighly more issues as I have containerized the frontend react app and backend spring boot api and seeing this CORS errors. I tried to add @CrossOrigin on the spring boot endpoint and also tried to add the serverUrl on the axios.post call. But it is still coming with error like u explained since the ports are different. Both containers are deployed on an EC2 instance using docker-compose remotely. Any recommendation as to how to go about resolving the issue. Much appreciate it.
@jokerbanny
@jokerbanny Жыл бұрын
Thack Thank Thank you very much ! 🥳
@jonamep
@jonamep 11 ай бұрын
The projects I work normally frontend and server are in complete different repos. So the approach in this case would be to add both localhost and production host at server cors config ?
@pawanbhatta8973
@pawanbhatta8973 15 күн бұрын
Thank you
@ELMlKO
@ELMlKO Жыл бұрын
real hero
@computefreely6898
@computefreely6898 8 ай бұрын
Amazing
@alextotun
@alextotun Жыл бұрын
Great! Thanks.)
@diwakardayal954
@diwakardayal954 3 ай бұрын
Thanks
@BobbyAlimardani
@BobbyAlimardani Жыл бұрын
I have a React js (axios) application on the client side and Node js (express) on the backend. I use aws iis ec2 as my hosting server. All works fine both in development and production, except when I connect to Veepn Chrome (from production) then my token header is not found. I don't use proxy, could this be the issue. I would really appreciate it if you could help me.
@daydream3025
@daydream3025 Жыл бұрын
Thank you man
@SamMeechWard
@SamMeechWard Жыл бұрын
You're welcome!
@shabariks7735
@shabariks7735 3 ай бұрын
i am just using normal react app even though i set it is still showing those error i am using vercel to deploy is there is any other way to fix those
@zonirinarakotoson6516
@zonirinarakotoson6516 Жыл бұрын
Thank you so much
@SamMeechWard
@SamMeechWard Жыл бұрын
You're most welcome
@abirhal2391
@abirhal2391 7 ай бұрын
i add proxy on packaj.js and when i run npm start i get this Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - options.allowedHosts[0] should be a non-empty string. how i can solve it , i spend 3day on it
@dhaouiaziz6611
@dhaouiaziz6611 11 ай бұрын
should i remove the proxy in prod ?
@onyejemeemmanuel94
@onyejemeemmanuel94 Жыл бұрын
Great but doesn't work for POST requests. All Post requests I make is somehow changed to a GET request by the proxy
@mamory2101
@mamory2101 Жыл бұрын
What would be a suggested way to do this?
6 ай бұрын
why do I need that proxy? why it would not work with localhost. Sorry - I am new in the field.
@thauveer465
@thauveer465 Жыл бұрын
thank you
@lamha1368
@lamha1368 Жыл бұрын
Config done run on localhost then work. But when deploy to hostname server VPS then not work. It's alway show error CORS. You can help to me root core ?
@pawankalyan9105
@pawankalyan9105 Жыл бұрын
THANKS MANNNNNNNNNNN
@avertry9529
@avertry9529 Жыл бұрын
Nice
@vladimirkuzmenkov7285
@vladimirkuzmenkov7285 6 ай бұрын
jeez man, you sure have huge eyes P.S. Thanks it helped!
@SamMeechWard
@SamMeechWard 6 ай бұрын
Always nice to meet a fan
@user-wp5rj3xm4l
@user-wp5rj3xm4l 11 ай бұрын
hi, how can i use 2 proxies in create-react-app?... by the way nice explanation.
@Jean44907
@Jean44907 Жыл бұрын
Thank ♥
@mubashirwaheed474
@mubashirwaheed474 Жыл бұрын
Thank you, Sam, for explaining that we have our own backend, but what about the case in which we are using third-party API?
@SamMeechWard
@SamMeechWard Жыл бұрын
This method only works if you're serving your react app from the same backend that you're making requests to. So you wouldn't be able to do this with a third party API, but those should already have the correct CORS configurations to allow you to make requests.
@mubashirwaheed474
@mubashirwaheed474 Жыл бұрын
@@SamMeechWard The API endpoint I was using didn't have CORS configured so I used a proxy to fix the issue Thanks
@pjborowiecki2577
@pjborowiecki2577 Жыл бұрын
@@SamMeechWard Thank you so much! Glad to have found your video and it helped me a lot. The only issue I am facing now is that this way, other routes (e.g., /admin) won't work after build - I am seeing "cannot GET /admin" messages. Routing works perfectly fine in development and I am using React Router Dom v. 6. Would you be so kind to explain this or point in the right direction? Thanks again! EDIT: Think I just solved it by adding app.use("/admin", (req, res) => { res.sendFile(path.join(__dirname, "dist/index.html")); }); to my server. Not sure whether this is a correct approach, but it does the trick. Still, Would love to hear how you would solve this. Thanks!
@kenthugo
@kenthugo Жыл бұрын
@@mubashirwaheed474 Have you fixed the issue? I have tried using the video's fix but it does not work in Production.
@mubashirwaheed474
@mubashirwaheed474 Жыл бұрын
@@kenthugoin order to fix my issue I used the netlify's serverless function to create a proxy (express server through which request is made to the api and then proxy -backend- send the data to the frontend
@zarefgamz2515
@zarefgamz2515 8 ай бұрын
vite proxy doesn't change axios configuration
@kennethobeng9127
@kennethobeng9127 2 ай бұрын
Lifesaver😪
@ashutosh887_
@ashutosh887_ Жыл бұрын
Great
@seunoyebode
@seunoyebode 4 ай бұрын
what if you're using remix?
@fuukowatty9817
@fuukowatty9817 4 ай бұрын
when im deploying on vercel it does not work
@DuyTran-ss4lu
@DuyTran-ss4lu Жыл бұрын
Cool
@anonymousghost5384
@anonymousghost5384 Жыл бұрын
Does it work in SSR?
@rp2804
@rp2804 Жыл бұрын
Thanks , so we can create proxy in next js too?
@SamMeechWard
@SamMeechWard Жыл бұрын
Yes you can, you could use http proxy middleware, or next js rewrites. However, deploying a next app is usually much different than a "traditional" react app and the plan probably won't be to bundle your client side react app with your server like it will with a react app that isn't using next. In next you're probably just going to use the next api or you're going to render your components on the server, or both. If you have another server that you're making API calls to, you might want to go down the CORS rabbit hole, but maybe using a reverse proxy like nginx.
@damilareoladele1309
@damilareoladele1309 2 ай бұрын
How can I add a second proxy link
AM Coder - Making Your Own Proxy Server to Avoid CORS Errors
12:58
Web Development with Alex Merced
Рет қаралды 13 М.
ИРИНА КАЙРАТОВНА - АЙДАХАР (БЕКА) [MV]
02:51
ГОСТ ENTERTAINMENT
Рет қаралды 873 М.
Эффект Карбонаро и бесконечное пиво
01:00
История одного вокалиста
Рет қаралды 6 МЛН
Универ. 13 лет спустя - ВСЕ СЕРИИ ПОДРЯД
9:07:11
Комедии 2023
Рет қаралды 3,3 МЛН
Why I No longer Hate CORS and Why you should too!
13:10
CoderOne
Рет қаралды 16 М.
DiagramGPT - Honest Review of Eraser AI
8:22
Sam Meech-Ward
Рет қаралды 110 М.
This is why you get CORS errors sometimes
13:11
Web Dev Cody
Рет қаралды 14 М.
All useEffect Mistakes Every Junior React Developer Makes
22:23
Learn CORS In 6 Minutes
6:06
Web Dev Simplified
Рет қаралды 702 М.
Why I don't use React-Query and tRPC in Next.js
18:58
ByteGrad
Рет қаралды 71 М.
Every React Concept Explained in 12 Minutes
11:53
Code Bootcamp
Рет қаралды 391 М.
Next.js Server Actions...  5 awesome things you can do
7:51
Beyond Fireship
Рет қаралды 251 М.
Где раздвижные смартфоны ?
0:49
Не шарю!
Рет қаралды 783 М.
Carregando telefone com carregador cortado
1:01
Andcarli
Рет қаралды 2,6 МЛН
ВЫ ЧЕ СДЕЛАЛИ С iOS 18?!
22:40
Overtake lab
Рет қаралды 79 М.
TOP-18 ФИШЕК iOS 18
17:09
Wylsacom
Рет қаралды 584 М.
5 НЕЛЕГАЛЬНЫХ гаджетов, за которые вас посадят
0:59
Кибер Андерсон
Рет қаралды 1,5 МЛН