Node.js CORS Joker Karakter Sorunu

Katılım
10 Ocak 2023
Mesajlar
11
Puanları
1
Yaş
25
Merhaba,

Şu anda bir Node.js uygulaması üzerinde çalışıyorum ve joker karakter kullanımından kaynaklandığını varsaydığım CORS ile ilgili bir sorun görüyorum. İşte sunucu tarafı kodumun bir örneği:
JavaScript:
const express = require('express');
const cors = require('cors');
const app = express();

// CORS Configuration
app.use(cors({
  origin: '*',
  methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
  optionsSuccessStatus: 204,
}));

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

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
});
İstemci tarafında temel bir GET isteği yapıyorum:
JavaScript:
fetch('http://localhost:3000/api/data')
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));
Ancak güvenlik endişelerini artıran bir CORS sorunu alıyorum:
Kod:
Access to fetch at 'http://localhost:3000/api/data' from origin 'http://localhost:8080' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header contains a wildcard, and requests with credentials are not allowed when the CORS credentials flag is 'true'.
Joker karakter kullanmanın güvenlik sorunlarına yol açabileceğini anladım, bu nedenle benzer bir senaryo hakkında scaler tarafından bu bloga rastladım ancak gerçekten anlayamadım. Birisi koduma bakıp Node.js uygulamamda CORS'u nasıl koruyacağım konusunda bana tavsiyede bulunabilir mi?

Zaman ayırdığınız ve yardımınız için teşekkür ederiz.
 

Yeni mesajlar

Forum istatistikleri

Konular
128,193
Mesajlar
915,738
Kullanıcılar
449,968
Son üye
ibrahimkalebayir38@gmail.

Yeni konular

Geri
Üst