Configuring CORS

You can configure CORS to be more specific about which origins are allowed and other settings. For example:

const corsOptions = {
  origin: 'http://example.com', // Allow only requests from this origin
  methods: 'GET,POST', // Allow only GET and POST methods
  allowedHeaders: 'Content-Type,Authorization', // Allow only these headers
};

app.use(cors(corsOptions));

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *