Here's a slice of the code I can run locally just fine:
Server:
var app = require('express')();
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
res.setHeader('Access-Control-Allow-Credentials', true);
next();
});
app.get('/', function (req, res) {
console.log("Got '/'");
res.status(200).send('Hello, world!');
});
var server = app.listen(process.env.PORT || '80', function () {
console.log('App listening on port %s', server.address().port);
});
var io = require('socket.io')(server);
io.on('connection', function (socket) {
console.log("connection");
});
Client: (TypeScript, run from a separate app on a different port, http://localhost:8080)
this.socket = io("http://localhost");
this.socket.on("connect", () => this.onSocketConnect());
When the server si deployed on Google App Engine, and the client is run locally with the address changed to http://my-app-id.appspot.com I get the following error:
WebSocket connection to 'ws://my-app-id.appspot.com/socket.io/?EIO=3&transport=websocket&sid=-Qr3YEeyZLk9K3zmAAAC' failed: Error during WebSocket handshake: Unexpected response code: 400
What's causing this and how can I fix it? Also, once I get this running, I plan to change to https, anything I need to be careful of there?