diff --git a/package.json b/package.json index f96cb6b28..8ed08841c 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,6 @@ "@types/wtfnode": "^0.7.0", "@typescript-eslint/eslint-plugin": "^4.7.0", "@typescript-eslint/parser": "^4.7.0", - "compression": "^1.7.4", "doctoc": "^1.4.0", "eslint": "^7.7.0", "eslint-config-prettier": "^6.0.0", @@ -77,6 +76,7 @@ "dependencies": { "@coder/logger": "1.1.16", "body-parser": "^1.19.0", + "compression": "^1.7.4", "cookie-parser": "^1.4.5", "env-paths": "^2.2.0", "express": "^5.0.0-alpha.8", diff --git a/src/node/plugin.ts b/src/node/plugin.ts index 7b65b6b5f..37700e183 100644 --- a/src/node/plugin.ts +++ b/src/node/plugin.ts @@ -251,7 +251,7 @@ export class PluginAPI { if (!p.routerPath) { throw new Error("plugin missing router path") } - if (!p.routerPath.startsWith("/") || p.routerPath.length < 2) { + if (!p.routerPath.startsWith("/")) { throw new Error(`plugin router path ${q(p.routerPath)}: invalid`) } if (!p.homepageURL) { diff --git a/test/plugin.test.ts b/test/plugin.test.ts index dfd7fac00..24326ded9 100644 --- a/test/plugin.test.ts +++ b/test/plugin.test.ts @@ -3,6 +3,7 @@ import * as express from "express" import * as fs from "fs" import * as path from "path" import { HttpCode } from "../src/common/http" +import { AuthType } from "../src/node/cli" import { codeServer, PluginAPI } from "../src/node/plugin" import * as apps from "../src/node/routes/apps" import * as httpserver from "./httpserver" @@ -26,6 +27,28 @@ describe("plugin", () => { const app = express.default() const wsApp = express.default() + + const common: express.RequestHandler = (req, _, next) => { + // Routes might use these arguments. + req.args = { + _: [], + auth: AuthType.None, + host: "localhost", + port: 8080, + "proxy-domain": [], + config: "~/.config/code-server/config.yaml", + verbose: false, + usingEnvPassword: false, + usingEnvHashedPassword: false, + "extensions-dir": "", + "user-data-dir": "", + } + next() + } + + app.use(common) + wsApp.use(common) + papi.mount(app, wsApp) app.use("/api/applications", apps.router(papi))