code-server/test/test-plugin/src/index.ts

52 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-01-13 22:25:39 +00:00
import * as cs from "code-server"
import * as fspath from "path"
2021-01-20 20:11:08 +00:00
import Websocket from "ws"
const wss = new Websocket.Server({ noServer: true })
2021-01-13 22:25:39 +00:00
export const plugin: cs.Plugin = {
displayName: "Test Plugin",
routerPath: "/test-plugin",
homepageURL: "https://example.com",
description: "Plugin used in code-server tests.",
init(config) {
config.logger.debug("test-plugin loaded!")
},
router() {
2021-01-13 22:26:11 +00:00
const r = cs.express.Router()
r.get("/test-app", (_, res) => {
res.sendFile(fspath.resolve(__dirname, "../public/index.html"))
})
2021-01-13 22:26:11 +00:00
r.get("/goland/icon.svg", (_, res) => {
res.sendFile(fspath.resolve(__dirname, "../public/icon.svg"))
})
return r
},
2021-01-20 20:11:08 +00:00
wsRouter() {
const wr = cs.WsRouter()
wr.ws("/test-app", (req) => {
wss.handleUpgrade(req, req.socket, req.head, (ws) => {
ws.send("hello")
})
})
return wr
},
applications() {
return [
{
name: "Test App",
version: "4.0.0",
iconPath: "/icon.svg",
path: "/test-app",
description: "This app does XYZ.",
homepageURL: "https://example.com",
},
]
},
}