Skip to content

Commit c2450d6

Browse files
authored
Merge pull request #2722 from cdr/root-plugin
2 parents 619934d + 8c3896c commit c2450d6

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
"@types/wtfnode": "^0.7.0",
5353
"@typescript-eslint/eslint-plugin": "^4.7.0",
5454
"@typescript-eslint/parser": "^4.7.0",
55-
"compression": "^1.7.4",
5655
"doctoc": "^1.4.0",
5756
"eslint": "^7.7.0",
5857
"eslint-config-prettier": "^6.0.0",
@@ -77,6 +76,7 @@
7776
"dependencies": {
7877
"@coder/logger": "1.1.16",
7978
"body-parser": "^1.19.0",
79+
"compression": "^1.7.4",
8080
"cookie-parser": "^1.4.5",
8181
"env-paths": "^2.2.0",
8282
"express": "^5.0.0-alpha.8",

src/node/plugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ export class PluginAPI {
251251
if (!p.routerPath) {
252252
throw new Error("plugin missing router path")
253253
}
254-
if (!p.routerPath.startsWith("/") || p.routerPath.length < 2) {
254+
if (!p.routerPath.startsWith("/")) {
255255
throw new Error(`plugin router path ${q(p.routerPath)}: invalid`)
256256
}
257257
if (!p.homepageURL) {

test/plugin.test.ts

+23
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as express from "express"
33
import * as fs from "fs"
44
import * as path from "path"
55
import { HttpCode } from "../src/common/http"
6+
import { AuthType } from "../src/node/cli"
67
import { codeServer, PluginAPI } from "../src/node/plugin"
78
import * as apps from "../src/node/routes/apps"
89
import * as httpserver from "./httpserver"
@@ -26,6 +27,28 @@ describe("plugin", () => {
2627

2728
const app = express.default()
2829
const wsApp = express.default()
30+
31+
const common: express.RequestHandler = (req, _, next) => {
32+
// Routes might use these arguments.
33+
req.args = {
34+
_: [],
35+
auth: AuthType.None,
36+
host: "localhost",
37+
port: 8080,
38+
"proxy-domain": [],
39+
config: "~/.config/code-server/config.yaml",
40+
verbose: false,
41+
usingEnvPassword: false,
42+
usingEnvHashedPassword: false,
43+
"extensions-dir": "",
44+
"user-data-dir": "",
45+
}
46+
next()
47+
}
48+
49+
app.use(common)
50+
wsApp.use(common)
51+
2952
papi.mount(app, wsApp)
3053
app.use("/api/applications", apps.router(papi))
3154

0 commit comments

Comments
 (0)