Move websocket routes into a separate app

This is mostly so we don't have to do any wacky patching but it also
makes it so we don't have to keep checking if the request is a web
socket request every time we add middleware.
This commit is contained in:
Asher
2020-11-05 12:58:37 -06:00
parent 9e09c1f92b
commit 7b2752a62c
8 changed files with 134 additions and 145 deletions

View File

@@ -2,6 +2,7 @@ import { Request, Router } from "express"
import proxyServer from "http-proxy"
import { HttpCode, HttpError } from "../common/http"
import { authenticated, ensureAuthenticated } from "./http"
import { Router as WsRouter } from "./wsRouter"
export const proxy = proxyServer.createProxyServer({})
proxy.on("error", (error, _, res) => {
@@ -82,7 +83,9 @@ router.all("*", (req, res, next) => {
})
})
router.ws("*", (req, _, next) => {
export const wsRouter = WsRouter()
wsRouter.ws("*", (req, _, next) => {
const port = maybeProxy(req)
if (!port) {
return next()