skip to Main Content

guys. I encountered an error while trying to use the signup form of my site it gives me this error Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at in the console of the browser.

I’ve read it’s about the fact that I use my PC as both server for the site itself and database where I want to store the user data, but I don’t know how to fix it. For database I use MongoDB if that’s something that is important. I’m not sure where the problem is so I will post the whole project from github. https://github.com/borki6a/Dreamsurvey

2

Answers


  1. You need something like

    app.use(require("cors")({
            origin: 'http://my-frontend-url-here',
            optionsSuccessStatus: 200
    }));

    in your server.js

    Login or Signup to reply.
  2. This error typically happens when a web app running on one origin requests an API from a server running on another origin.

    I think you can configure some http headers to solve the issue:

    In your backend API(Suppose using Express.js)

    app.use(cors({
      origin: 'http://localhost:4200', //URL of your Angular application
      methods: ['GET', 'POST', 'PUT', 'DELETE'],
      allowedHeaders: ['Content-Type']
    }));
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search