You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 11, 2022. It is now read-only.
WebSocket connection to 'wss://alchemy-games.herokuapp.com/' failed: Error during WebSocket handshake: Unexpected response code: 200
server.js
const {createServer} = require('http');
const express = require('express');
const path = require('path');
const util = require('util')
const WebSocket = require('ws');
const controller = require('./game.js');
const rooms = {};
const PORT = process.env.PORT || 5000;
const server = express()
.use(express.static(path.resolve(__dirname, 'build')))
.use('/', (req, res) => {
res.sendFile(path.resolve(__dirname, 'build'));
})
.listen(PORT, () => console.log(`Listening on ${ PORT }`));
var wss = new WebSocket.Server({ server: server });
wss.on('connection', function(wsClient){
console.log(wsClient);
});
app.js
import React, { Component } from 'react'
const HOST = window.location.origin.replace(/^http/, 'ws');
const socket = new WebSocket(HOST);
class GameProvider extends Component {
constructor(){
super();
this.state = {}
socket.onopen = (e) => {
console.log("sockets have been connected", e)
}
}
}
export default class extends Component {
render(){
return (
<GameProvider />
)
}
}
I was able to get my project working by removing the build back, removing /build from the .gitignore, and changing start: node server.js in my package.json file.
I am sure there is a lot that I am missing from not using this build, but I just couldn't find a way to get sockets to work with this.