Creating the backend server
Create the src/server
folder and add to it a file named server.ts
with the content shown in Listing 9.8.
Listing 9.8: The contents of the server.ts file in the src/server folder
import { createServer } from "http";
import express, {Express } from "express";
import { testHandler } from "./testHandler";
import httpProxy from "http-proxy";
import helmet from "helmet";
const port = 5000;
const expressApp: Express = express();
const proxy = httpProxy.createProxyServer({
target: "http://localhost:5100", ws: true
});
expressApp.use(helmet());
expressApp.use(express.json());
expressApp.post("/test", testHandler);
expressApp.use(express.static("static"));
expressApp.use(express.static("node_modules/bootstrap/dist"));
expressApp.use((req, resp) => proxy.web(req, resp));
const server = createServer(expressApp);
server.on('upgrade', (req, socket, head...