Locally everything works, nodejs:
io = require('socket.io')(server, {
cors: {
origin: '*',
}
});
Next 10.0.3 client:
import { io } from 'socket.io-client';
...
const [socket, setSocket] = useState<SocketIOClient.Socket>();
useEffect(() => {
(async () => {
if (!socket) {
setSocket( io('ws://localhost:3030') );
} else {
socket.on('connection', () => {
console.log('connected_ ');
});
socket.on('disconnect', () => {
socket.disconnect();
});
socket.on('message', (message: any) => {
...
});
}
})();
return () => {
if (socket) {
socket.disconnect();
}
}
}, [socket]);
Deployed my REST Api Gateway: /{proxy+}, client certs, API keys provides SSL endpoints all working.
Whatever config -> Api Gateway for Websocket, my React client logs every 1 sec:
Access to XMLHttpRequest at 'https://aby8ysdpcfg.execute-api.ap-southeast-2.amazonaws.com/production/?EIO=4&transport=polling&t=NT5V7jb' from origin
'https://abcvds4mhutxa9a.cloudfront.net' 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.
React Client: tried params to io() all combinations of:
{
extraHeaders: {
Authorization: `Bearer ${user.token}`,
"x-api-key": `${process.env.API_GATEWAY_KEY}`
},
path: '/production',
port: 80
}
Api Gateway: tried Routes, Stages, Settings, but doesn't hit the server or show traffic on the gateway Dashboard. (Routes $connect, $default as HTTP and AWS Service -> EC2 (subdomain?)). wscat connects to the wss://.../production and shows traffic on the Dashboard.
question from:
https://stackoverflow.com/questions/65929179/api-gateway-websocket-cant-connect-to-aws-ec2-socket-io 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…