When I send POST request from Vite.js app (localhost:5173) to backend I get correct response but my data doesn’t come. I mean My request goes correctly but the data is not coming
Hello, first of all that is my vite.config.js
file:
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
export default defineConfig({
plugins: [react()],
server: {
port: 5173,
},
});
I have configured cors options in my nodejs express backend server like that:
app.use(cors({
origin: "http://localhost:5173",
credentials: true
}));
and after runnin my Vite.js app on localhost:5173 then my CORS error problem fixed then when I send post request to login in my webpage, my backend response is 200 but my credentials are not come. first I thought reason of that axios withCredentials options is not true for that reason I added whit options in my API.js file to change defaul credentials like that:
import axios from 'axios'
axios.defaults.withCredentials = true;
But I get same error again. Actually I don’t get error just response is correct but my data doesn’t come. When I create react app without vite it works correctly but in vite.js I get this issue. I think reason of that is vite.js configuration.
That’t my response headers:
HTTP/1.1 200 OK
Date: Fri, 10 May 2024 21:08:11 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 158
Connection: keep-alive
X-Powered-By: Express
Access-Control-Allow-Origin: http://localhost:5173
Vary: Origin
Access-Control-Allow-Credentials: true
Nijat Mansimov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.