Unable to establish WebSocket connection between React app and Express server

When I try to establish a WebSocket connection between my React app and Express server, I receive the following error:

Connection closed before receiving a handshake response

Code on the client:

import React from 'react';

class AppComponent extends React.Component {
  componentDidMount() {
    this.ws = new WebSocket('ws://localhost:8080')
    this.ws.onmessage = (event) => this.setState({users: Object.values(JSON.parse(event.data))})
    this.ws.onerror = () => this.setState({error: 'WebSocket error'})
    this.ws.onclose = (event) => !event.wasClean && this.setState({error: `WebSocket error: ${event.code} ${event.reason}`})
  }
  componentWillUnmount() {
    this.ws.close()
  }
  render() {
    return (
      <div className="index">
        WebSocket App
      </div>
    );
  }
}

export default AppComponent;

Code on the server:

"use strict";

const port = 8080;

const express = require("express");
const app = express();
const bodyParser = require("body-parser");
// const server = require("http").createServer(app);

const server = app.listen(port, () => {
  console.log(`listening on ${port}`);
});

const io = require("socket.io")(server);

app.use(bodyParser.urlencoded({ extended: false } ));
app.use(express.static("static"));

const { PRINT_TIME, statuses, actions, allowedActions } =
    require("./constants");
const { update, marshalState } = require("./stateUtils");

let state = {
    status: statuses.IDLE,
    progress: 0,
    elapsed_time: 0,
    time_remaining: PRINT_TIME
};

io.set("origins", "http://localhost:8001");

io.on("connection", ws => {
    console.log("PRINTER CONNECTED");

    ws.on("message", msg => {
        if(!allowedActions[state.status] ||
            !allowedActions[state.status].includes(msg))
            return io.send(
                JSON.stringify({
                    error:
                        `Action: ${msg} not allowed for status: ${state.status}`
                }));

        switch (msg) {
        case actions.PRINT:
        case actions.RESUME:
            state = update(state, statuses.BUSY);
            break;
        case actions.CANCEL:
            state = update(state, statuses.CANCELED);
            break;
        case actions.PAUSE:
            state = update(state, statuses.PAUSED);
            break;
        case actions.DONE:
            state = update(state, statuses.DONE);
            break;
        case actions.PRINT_AGAIN:
            state = update(state, statuses.PRINT_AGAIN);
            break;
        default:
            break;
        }
    });

    setInterval(() => {
        if(state.status === statuses.BUSY)
            state = update(state, statuses.BUSY);
        console.log(marshalState(state));
        ws.broadcast.send(JSON.stringify(marshalState(state)));
    },
    1000);
});

io.on("error", err => console.log(err));

app.get('/', (req, res) => {
  res.send('cookies')
});

What seems to be the problem? It seems like the error is server-side but I am not sure what is missing.