1

I added headers on the server side

 res.setHeader('Access-Control-Allow-Origin','*');

 res.setHeader('Access-Control-Allow-Methods',"OPIONS,GET,POST,PUT,PATCH,DELETE");

 res.setHeader('Access-Control-Allow-Headers','Content-Type , Authorization');

But I still get the error on reactjs I used fetch for send and take data. Also I used from the header 'Access-Control-Allow-Origin':'*' On the ractjs

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
zahraei
  • 79
  • 1
  • 9

1 Answers1

2

you can use pretty good library called cors which can do all your configs for you. here check it cors. you can configure it in your app.js like so:

const express = require('express');
const app = express();
const cors = require('cors')
app.use(cors());

if this does not work, you probably forgot to add proxy to your client's package.json

iLiA
  • 3,053
  • 4
  • 23
  • 45