From 91303d4e40465a82f9652210992fd48b7e89b27d Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Wed, 2 Jun 2021 13:27:55 -0700 Subject: [PATCH] refactor: make ensureAuthenticated async --- src/node/routes/domainProxy.ts | 4 ++-- src/node/routes/pathProxy.ts | 6 +++--- src/node/routes/static.ts | 2 +- typings/pluginapi.d.ts | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/node/routes/domainProxy.ts b/src/node/routes/domainProxy.ts index 26a3fa6f..56b0ea1b 100644 --- a/src/node/routes/domainProxy.ts +++ b/src/node/routes/domainProxy.ts @@ -74,14 +74,14 @@ router.all("*", async (req, res, next) => { export const wsRouter = WsRouter() -wsRouter.ws("*", (req, _, next) => { +wsRouter.ws("*", async (req, _, next) => { const port = maybeProxy(req) if (!port) { return next() } // Must be authenticated to use the proxy. - ensureAuthenticated(req) + await ensureAuthenticated(req) proxy.ws(req, req.ws, req.head, { ignorePath: true, diff --git a/src/node/routes/pathProxy.ts b/src/node/routes/pathProxy.ts index 789fa5c1..e3200174 100644 --- a/src/node/routes/pathProxy.ts +++ b/src/node/routes/pathProxy.ts @@ -45,13 +45,13 @@ export function proxy( }) } -export function wsProxy( +export async function wsProxy( req: pluginapi.WebsocketRequest, opts?: { passthroughPath?: boolean }, -): void { - ensureAuthenticated(req) +): Promise { + await ensureAuthenticated(req) _proxy.ws(req, req.ws, req.head, { ignorePath: true, target: getProxyTarget(req, opts?.passthroughPath), diff --git a/src/node/routes/static.ts b/src/node/routes/static.ts index 5ba6983e..29a1ad3b 100644 --- a/src/node/routes/static.ts +++ b/src/node/routes/static.ts @@ -18,7 +18,7 @@ router.get("/(:commit)(/*)?", async (req, res) => { // Used by VS Code to load extensions into the web worker. const tar = getFirstString(req.query.tar) if (tar) { - ensureAuthenticated(req) + await ensureAuthenticated(req) let stream: Readable = tarFs.pack(pathToFsPath(tar)) if (req.headers["accept-encoding"] && req.headers["accept-encoding"].includes("gzip")) { logger.debug("gzipping tar", field("path", tar)) diff --git a/typings/pluginapi.d.ts b/typings/pluginapi.d.ts index f7797b6d..881aa1fb 100644 --- a/typings/pluginapi.d.ts +++ b/typings/pluginapi.d.ts @@ -145,12 +145,12 @@ export const proxy: ProxyServer /** * Middleware to ensure the user is authenticated. Throws if they are not. */ -export function ensureAuthenticated(req: express.Request, res?: express.Response, next?: express.NextFunction): void +export function ensureAuthenticated(req: express.Request, res?: express.Response, next?: express.NextFunction): Promise /** * Returns true if the user is authenticated. */ -export function authenticated(req: express.Request): boolean +export function authenticated(req: express.Request): Promise /** * Replace variables in HTML: TO, BASE, CS_STATIC_BASE, and OPTIONS.