Problème d'informations d'identification CORS Node.js - Besoin d'aide pour résoudre l'erreur

Bonjour,

J'espère que vous pourrez m'aider avec un problème lié à CORS dans mon application Node.js. Voici un exemple de mon code côté serveur :
JavaScript:
const express = require('express');
const cors = require('cors');
const app = express();

// CORS Configuration
app.use(cors({
  origin: 'http://localhost:8080',
  credentials: true,
}));

// ... other middleware and routes ...

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
});
Côté client, je fais la requête suivante :
JavaScript:
fetch('http://localhost:3000/api/data', {
  method: 'GET',
  credentials: 'include',
})
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));
Mais j'obtiens l'erreur CORS suivante :
Code:
Access to fetch at 'http://localhost:3000/api/data' from origin 'http://localhost:8080' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Credentials' header in the response is 'false' which must be 'true' when the request's credentials mode is 'include'.
J'ai défini les informations d'identification : true sur le serveur, mais il semble qu'il y ait toujours un problème, puis je suis tombé sur ce blog de scaler sur le même sujet mais je n'ai pas pu le comprendre complètement. Pourriez-vous bien vouloir évaluer mon code et proposer des suggestions pour résoudre cette erreur d'informations d'identification CORS ?

Merci pour vos connaissances.
 

HeySunshine

💃🏻
VIB
Je pense que @Sanid peut aider

Please Help American Horror Story GIF by AHS




Sorry @Sanid

Sorry Watch Out GIF by Laff
 
Haut