Access to fetch has been blocked by CORS policy: No 'Access-Control-Allow-Origin' - FIXED!

Поделиться
HTML-код
  • Опубликовано: 27 авг 2024
  • Access to fetch at 'localhost:4000/api/courses' from origin 'localhost:3001' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
    NOTE: You can also try: Chrome Browser FLAGS fix: • CORS policy Chrome Bro...
    codes:
    - npm install cors
    - const cors = require('cors');
    - app.use(cors());
    Solution!

Комментарии • 96

  • @dreadrockadrian
    @dreadrockadrian Год назад +18

    You have it turned around. You're ONLY allowed to fetch data from the same site. Its a Cross Origin problem - hence CORS.

  • @oscheka
    @oscheka 2 года назад +1

    Thank you very much. Have searched the web for hrs and finally got to solve it using your technique

  • @snehanigam4489
    @snehanigam4489 6 месяцев назад +2

    i am not using any api in my project but i want to fetch data from database to show it on my frontend i am facing cors error will this work for me

  • @marcelomoraes1341
    @marcelomoraes1341 Год назад +4

    Man! You're a genius! Thank you so much. Great video and strict to the point!

  • @jamshidabdukarimov8946
    @jamshidabdukarimov8946 2 года назад +3

    Briliant, just what I needed! Thank you bro

  • @informativeKarachiWala
    @informativeKarachiWala 2 года назад +5

    Bravo...! This helped me alot... Thanks Buddy for the help

  • @stinasmeds3120
    @stinasmeds3120 2 года назад +4

    Excellent, just what I needed! Thank you

  • @AkashDabhane10
    @AkashDabhane10 Год назад +1

    Thanks man❤, I was solving this issue from two days and finally have fix it.

  • @Anas-gs8xh
    @Anas-gs8xh Год назад

    Thanks pale, you're a life savior

  • @sagarsonkar6961
    @sagarsonkar6961 Год назад +2

    ReferenceError: require is not defined

  • @mdzaidsiddiqui4262
    @mdzaidsiddiqui4262 2 года назад +3

    What should I do if I'm fetching data from an online API to my localhost and get this error?

    • @CoderDmitri
      @CoderDmitri  2 года назад +2

      can you provide an API that causes this?

    • @rasuliskandarov9023
      @rasuliskandarov9023 Год назад

      solution here.
      stackoverflow.com/questions/67661993/cors-issue-in-public-api-call-from-angular-but-works-fine-directly-from-browsers

  • @zarzzzar
    @zarzzzar Год назад +1

    What if it says require is not defined?

  • @queenofsheba8275
    @queenofsheba8275 Год назад +1

    when i add "const cors = require('cors')"; i get a nodemon error : "[nodemon] app crashed - waiting for file changes before starting...", and it does not fix the original error either.. why is this happening

    • @CoderDmitri
      @CoderDmitri  Год назад +1

      try npm i cors, and try to position code in different locations, like after all other app.use() or after all imports , cause sometimes it affects it

    • @queenofsheba8275
      @queenofsheba8275 Год назад

      @CoderDmitri thank you. It was the position that was the problem .

  • @joaquincataldo8046
    @joaquincataldo8046 Год назад +1

    thanks man ! useful and straight to the point

  • @cps7257
    @cps7257 Год назад

    i have to comment and like ur vid. It saved my life

  • @maksudurprio9260
    @maksudurprio9260 Год назад +1

    Hi i 've used cors already. And i deployed my server on vercel. Still i 'm having that error. Can u help me?

    • @BEEKESHAVTOMAR-rc9ks
      @BEEKESHAVTOMAR-rc9ks Год назад +1

      Was your error solved, I am getting the same error now, Please help if it is solved

    • @ishadii
      @ishadii Год назад

      @@BEEKESHAVTOMAR-rc9ks i'm getting the same

  • @Daniel-dy2te
    @Daniel-dy2te 2 года назад +3

    Thanks, helped me a lot!

  • @cryptic-menace
    @cryptic-menace 21 день назад

    Thanks bro ,🎉 you've saved me

  • @tiagoblauth10
    @tiagoblauth10 Год назад +1

    You saved another dev, many thanks

  • @anantjain9679
    @anantjain9679 2 года назад +1

    after installing cors , i didnt got server.js , where to get server.js

  • @johnxina3536
    @johnxina3536 Год назад +2

    Thank you very much

  • @brightnessoflife3594
    @brightnessoflife3594 2 года назад

    Thank you for this great informative video.

  • @wandersongomes8405
    @wandersongomes8405 3 года назад +2

    Valeu irmao. Era justamente isto que eu estava procurando. Muitissimo obrigado.

  • @jaafarty2673
    @jaafarty2673 3 месяца назад

    i thought i found the solution but still same error for cors

  • @gabrielfono844
    @gabrielfono844 2 года назад +1

    what if I want to do it using React and php
    I really need help

    • @CoderDmitri
      @CoderDmitri  2 года назад +1

      100% works in React and Next.js, but not sure about PHP, because I don't use PHP language.

  • @salimabrinsi4074
    @salimabrinsi4074 Год назад

    my error is fixed , thank you so much

  • @user-ks7hl1zi7c
    @user-ks7hl1zi7c 7 месяцев назад

    Without providing the requested files, any further actions are impossible. All further messages from you will be ignored.

  • @joelohkaishunhiroyukifujik5700

    Sorry can someone help me, my code shows that require is not defined

  • @furkaneravsar9627
    @furkaneravsar9627 8 месяцев назад

    Thanks man. You are a savior :D

  • @062_ankitkumar6
    @062_ankitkumar6 2 года назад +2

    it worked.thanks man

    • @CoderDmitri
      @CoderDmitri  2 года назад +1

      Excellent! Well done for not giving up and searching for solutions! =)

  • @adolfotux
    @adolfotux 4 месяца назад

    Thx, it works.
    Also, i found another solution, so you don't need to install cors dependecy, but, only works If your server is express.js based.
    app.use(function (req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    next();
    })

  • @pierrot1255
    @pierrot1255 6 месяцев назад

    Thank you so much for your help!

  • @user-so8xc6nq5x
    @user-so8xc6nq5x 2 года назад +3

    Не роботает

    • @CoderDmitri
      @CoderDmitri  2 года назад

      make a video with errors you are getting, let me have a look

    • @user-so8xc6nq5x
      @user-so8xc6nq5x 2 года назад

      @@CoderDmitri React и PHP интегрируем бекенд и фронтенд. Сюда зашёл посмотрел там всё работает.

  • @user-bt6bo8lb4l
    @user-bt6bo8lb4l Год назад

    very helpful Dimitri

  • @frostplays4911
    @frostplays4911 2 года назад +1

    what app r u using?

    • @CoderDmitri
      @CoderDmitri  2 года назад

      ditto, copy and paste clip board manager... ditto-cp.sourceforge.io/

  • @shekhar4319
    @shekhar4319 Год назад

    Thanks a lot and nice thi9ng is that u r straight to the point

  • @Podcast_Shorts591
    @Podcast_Shorts591 Год назад

    How to make same thing in nextjs

  • @laflame1896
    @laflame1896 Год назад +1

    Thank you so much!

  • @programming-with-suraj
    @programming-with-suraj Год назад +1

    help me bro , this is not working

  • @midlton555
    @midlton555 Год назад +1

    THANK YOU

  • @RiyazBaig-yq9fy
    @RiyazBaig-yq9fy Год назад

    hey bro I want Server.js and App.js coding

  • @jyotikamat1787
    @jyotikamat1787 2 года назад

    Thank you , error resolved

  • @malekalbawaih
    @malekalbawaih Месяц назад

    thank you so much

  • @mustaphaloabar8430
    @mustaphaloabar8430 2 года назад +1

    hey you loooooooooooooooooooove u biggggggg respect

  • @roeko10
    @roeko10 Год назад

    You saved me! thanks!

  • @unbreakablejourney2432
    @unbreakablejourney2432 Год назад

    it work. thanks dude

  • @felipefregginrules
    @felipefregginrules Год назад

    THANK YOU SOOOO MUCH!

  • @yashgaikwad2924
    @yashgaikwad2924 Год назад

    Thank you

  • @talipckl
    @talipckl 2 года назад

    this is not wroking in heroku backend project haaa

  • @075_mmshahriarshakil2
    @075_mmshahriarshakil2 10 месяцев назад

    thanks man u save my one day

  • @ritulbhatnagar1502
    @ritulbhatnagar1502 2 года назад +1

    thanks 🙏🙏🙏

  • @albertnt7327
    @albertnt7327 2 года назад

    THANK YOU !!!

  • @mirzamurodrahimberdiyev3869
    @mirzamurodrahimberdiyev3869 2 года назад +1

    thank you bro

  • @rafikzahra6379
    @rafikzahra6379 2 года назад

    Thanks 🙏🏻

  • @user-xs8bz6nl3y
    @user-xs8bz6nl3y Год назад

    Thanks

  • @athena76308
    @athena76308 2 года назад +1

    Thankss 😊

  • @adameelmadani
    @adameelmadani Месяц назад

    thanks man

  • @elseri1883
    @elseri1883 3 года назад

    thankss man it worked!!

  • @subbuerikinaboina1044
    @subbuerikinaboina1044 Год назад

    Awesome awesome... 👏

  • @Ari1090
    @Ari1090 2 года назад

    Thx

  • @thecoderabbi
    @thecoderabbi 2 года назад

    FontSize!

  • @mevn6807
    @mevn6807 Год назад

    the best

  • @user-tb3mm6dl3z
    @user-tb3mm6dl3z 2 месяца назад

    Ща попробую

  • @dharamjitsingh6505
    @dharamjitsingh6505 2 года назад

    Zoom in

  • @leotaylor9001
    @leotaylor9001 3 месяца назад

    Be very very quiet.

  • @TheHeavyassaulter
    @TheHeavyassaulter Год назад

    How do you access the god damn server, guys not everyone that watches these videos is a programmer you kjwo that right? 😅

    • @rimabouazra3105
      @rimabouazra3105 Год назад

      same. can u find a solution ?

    • @TheHeavyassaulter
      @TheHeavyassaulter Год назад

      @@rimabouazra3105 yeah I found a solution. Just disable the damn ad blocker, they actually do this to the websites believe it or not. When I finally disabled them I could use websites again...

  • @anantaprajapati6801
    @anantaprajapati6801 6 месяцев назад

    thakyou

  • @MotionTeds
    @MotionTeds 2 года назад

    isnt this the same? because i use this and stil didnt work
    import cors from "cors";
    app.use(cors({credentials:true, optionSuccessStatus:200, origin:'localhost:3000'}));

  • @nattamon59jant78
    @nattamon59jant78 2 года назад

    Thank you