Using NodeJS as backend and React as frontend. Frontend uses axios to do post/get requests. Everything is working well in development with localhost:5000 as server and localhost:3000 as client.
However, when I deploy my server and client to websites, they fail to work. I have changed the respective localhost addresses to the website's address but to no avail. Here is how I set my backend code:
const server = express();
server.use(cors({origin: "https://frontendwebsitename.com", credentials: true}));
server.use(express.json());
server.use(express.urlencoded({extended:true}))
In my frontend website console, I get this error: Access to XMLHttpRequest at 'https://backendwebsitename.herokuapp.com/fetchDefaultSearch' from origin 'https://frontendwebsitename.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Any ideas?