From 0abbc9789ebcd30e43acf51052d03491e82aa007 Mon Sep 17 00:00:00 2001 From: Asher Date: Fri, 12 Feb 2021 15:19:26 -0600 Subject: [PATCH 1/3] Allow plugins to register at the root Unfortunately we have existing plugins with routes there which we cannot move. --- src/node/plugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) { From de117535698c85c893212435c80449dbc45ac0ef Mon Sep 17 00:00:00 2001 From: Asher Date: Fri, 12 Feb 2021 16:04:48 -0600 Subject: [PATCH 2/3] Fill req.args for tests --- test/plugin.test.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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)) From 8c3896cf4060651b8b95a4e35b5f5b94bc463d11 Mon Sep 17 00:00:00 2001 From: Asher Date: Fri, 12 Feb 2021 16:06:41 -0600 Subject: [PATCH 3/3] Move compression to deps from dev deps --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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",