skip to Main Content

i have tried to upload mern project on cpanel but always get cors problem
I have use this function in express js but same problem occurred

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 , Authorization');
    res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
    next();
});

Also tried to use cors package but same error
Express work on poet 5001 and react on port 4000
Any solution can try

2

Answers


  1. Chosen as BEST ANSWER

    thanks all , it was cpanel cors problem and another one i need to add is bcrypt package cause an error so i used bcryptjs library


  2. try npm package cors.
    and use it as a middleware in server file .

    app.use(cors())
    

    this means allow all – *

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search