Archived
1
0

Merge pull request #2722 from cdr/root-plugin

This commit is contained in:
Asher 2021-02-12 16:07:23 -06:00 committed by GitHub
commit c2450d6bf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 2 deletions

View File

@ -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",

View File

@ -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) {

View File

@ -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))