Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions src/node/vscodeSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { logger } from "@coder/logger"
import express from "express"
import * as http from "http"
import * as path from "path"
import { HttpCode } from "../common/http"
import { HttpCode, HttpError } from "../common/http"
import { listen } from "./app"
import { errorHandler } from "./routes/errors"
import { canConnect } from "./util"

export interface EditorSessionEntry {
Expand Down Expand Up @@ -44,24 +45,18 @@ export async function makeEditorSessionManagerServer(
async (req, res) => {
const filePath = req.query.filePath
if (!filePath) {
res.status(HttpCode.BadRequest).send("filePath is required")
return
}
try {
const socketPath = await editorSessionManager.getConnectedSocketPath(filePath)
const response: GetSessionResponse = { socketPath }
res.json(response)
} catch (error: unknown) {
res.status(HttpCode.ServerError).send(error)
throw new HttpError("filePath is required", HttpCode.BadRequest)
}
const socketPath = await editorSessionManager.getConnectedSocketPath(filePath)
const response: GetSessionResponse = { socketPath }
res.json(response)
},
)

router.post<{}, string, AddSessionRequest | undefined>("/add-session", async (req, res) => {
const entry = req.body?.entry
if (!entry) {
res.status(400).send("entry is required")
return
throw new HttpError("entry is required", HttpCode.BadRequest)
}
editorSessionManager.addSession(entry)
res.status(200).send("session added")
Expand All @@ -70,13 +65,14 @@ export async function makeEditorSessionManagerServer(
router.post<{}, string, DeleteSessionRequest | undefined>("/delete-session", async (req, res) => {
const socketPath = req.body?.socketPath
if (!socketPath) {
res.status(400).send("socketPath is required")
return
throw new HttpError("socketPath is required", HttpCode.BadRequest)
}
editorSessionManager.deleteSession(socketPath)
res.status(200).send("session deleted")
})

router.use(errorHandler)

const server = http.createServer(router)
try {
await listen(server, { socket: codeServerSocketPath })
Expand Down
Loading