Archived
1
0

refactor: make ensureAuthenticated async

This commit is contained in:
Joe Previte 2021-06-02 13:27:55 -07:00
parent 0cdbd33b46
commit 91303d4e40
No known key found for this signature in database
GPG Key ID: 2C91590C6B742C24
4 changed files with 8 additions and 8 deletions

View File

@ -74,14 +74,14 @@ router.all("*", async (req, res, next) => {
export const wsRouter = WsRouter() export const wsRouter = WsRouter()
wsRouter.ws("*", (req, _, next) => { wsRouter.ws("*", async (req, _, next) => {
const port = maybeProxy(req) const port = maybeProxy(req)
if (!port) { if (!port) {
return next() return next()
} }
// Must be authenticated to use the proxy. // Must be authenticated to use the proxy.
ensureAuthenticated(req) await ensureAuthenticated(req)
proxy.ws(req, req.ws, req.head, { proxy.ws(req, req.ws, req.head, {
ignorePath: true, ignorePath: true,

View File

@ -45,13 +45,13 @@ export function proxy(
}) })
} }
export function wsProxy( export async function wsProxy(
req: pluginapi.WebsocketRequest, req: pluginapi.WebsocketRequest,
opts?: { opts?: {
passthroughPath?: boolean passthroughPath?: boolean
}, },
): void { ): Promise<void> {
ensureAuthenticated(req) await ensureAuthenticated(req)
_proxy.ws(req, req.ws, req.head, { _proxy.ws(req, req.ws, req.head, {
ignorePath: true, ignorePath: true,
target: getProxyTarget(req, opts?.passthroughPath), target: getProxyTarget(req, opts?.passthroughPath),

View File

@ -18,7 +18,7 @@ router.get("/(:commit)(/*)?", async (req, res) => {
// Used by VS Code to load extensions into the web worker. // Used by VS Code to load extensions into the web worker.
const tar = getFirstString(req.query.tar) const tar = getFirstString(req.query.tar)
if (tar) { if (tar) {
ensureAuthenticated(req) await ensureAuthenticated(req)
let stream: Readable = tarFs.pack(pathToFsPath(tar)) let stream: Readable = tarFs.pack(pathToFsPath(tar))
if (req.headers["accept-encoding"] && req.headers["accept-encoding"].includes("gzip")) { if (req.headers["accept-encoding"] && req.headers["accept-encoding"].includes("gzip")) {
logger.debug("gzipping tar", field("path", tar)) logger.debug("gzipping tar", field("path", tar))

View File

@ -145,12 +145,12 @@ export const proxy: ProxyServer
/** /**
* Middleware to ensure the user is authenticated. Throws if they are not. * 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<void>
/** /**
* Returns true if the user is authenticated. * Returns true if the user is authenticated.
*/ */
export function authenticated(req: express.Request): boolean export function authenticated(req: express.Request): Promise<void>
/** /**
* Replace variables in HTML: TO, BASE, CS_STATIC_BASE, and OPTIONS. * Replace variables in HTML: TO, BASE, CS_STATIC_BASE, and OPTIONS.