Olá a todos,
Sou novo no socket.io. Tenho o seguinte código no meu servidor NodeJs / Express
const http = require('http');
const socketIo = require('socket.io');
const app = express();
const server = http.createServer(app);
const io = socketIo(server);
io.on('connection', socket => {
console.log('New client connected');
socket.on('disconnect', () => console.log('Client disconnected'));
socket.emit('FromAPI', 'hello');
});
//My port here is 8848
app.listen(app.get('port'), () => {
logger.log('info', `Server started at :${app.get('port')}`);
});
E o código a seguir no aplicativo Client React e no meu aplicativo react está hospedado na porta 3000 como http: // localhost : 3000
import socketIO from 'socket.io-client';
componentDidMount() {
const endPoint = 'http://127.0.0.1:8848';
const socket = socketIO(endPoint);
socket.on('FromAPI', data => console.log(data));
}
Com este código, obtive o seguinte erro no console do navegador:
polling-xhr.js: 263 GET http://127.0.0.1 : 8848 / socket.io /? EIO = 3 & transport = polling & t = MMT-4kl 405 (método não permitido)
Falha ao carregar http://127.0.0.1 : 8848 / socket.io /? EIO = 3 & transport = polling & t = MMT-Aso: O valor do cabeçalho 'Access-Control-Allow-Origin' na resposta não deve ser o curinga '*' quando o modo de credenciais da solicitação é 'incluir'. Portanto, o acesso de origem ' http: // localhost : 3000' não é permitido. O modo de credenciais de solicitações iniciadas pelo XMLHttpRequest é controlado pelo atributo withCredentials.
Alguém por favor me ajude com este problema.
Então, fechado e sem solução? :(
Tendo o mesmo problema, não consigo encontrar uma solução ..
tendo o mesmo problema sem solução
Comentários muito úteis
Então, fechado e sem solução? :(