mirror of
https://github.com/coder/code-server.git
synced 2024-12-26 03:05:00 +03:00
refactor: make ensureAuthenticated async
This commit is contained in:
parent
0cdbd33b46
commit
91303d4e40
@ -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,
|
||||
|
@ -45,13 +45,13 @@ export function proxy(
|
||||
})
|
||||
}
|
||||
|
||||
export function wsProxy(
|
||||
export async function wsProxy(
|
||||
req: pluginapi.WebsocketRequest,
|
||||
opts?: {
|
||||
passthroughPath?: boolean
|
||||
},
|
||||
): void {
|
||||
ensureAuthenticated(req)
|
||||
): Promise<void> {
|
||||
await ensureAuthenticated(req)
|
||||
_proxy.ws(req, req.ws, req.head, {
|
||||
ignorePath: true,
|
||||
target: getProxyTarget(req, opts?.passthroughPath),
|
||||
|
@ -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))
|
||||
|
4
typings/pluginapi.d.ts
vendored
4
typings/pluginapi.d.ts
vendored
@ -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<void>
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
Loading…
Reference in New Issue
Block a user