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

@@ -4,12 +4,12 @@ import { promises as fs } from "fs"
import http from "http"
import * as httpolyglot from "httpolyglot"
import { DefaultedArgs } from "./cli"
import { handleUpgrade } from "./http"
import { handleUpgrade } from "./wsRouter"
/**
* Create an Express app and an HTTP/S server to serve it.
*/
export const createApp = async (args: DefaultedArgs): Promise<[Express, http.Server]> => {
export const createApp = async (args: DefaultedArgs): Promise<[Express, Express, http.Server]> => {
const app = express()
const server = args.cert
@@ -39,9 +39,10 @@ export const createApp = async (args: DefaultedArgs): Promise<[Express, http.Ser
}
})
handleUpgrade(app, server)
const wsApp = express()
handleUpgrade(wsApp, server)
return [app, server]
return [app, wsApp, server]
}
/**