Provide WsRouter to plugins

This commit is contained in:
Asher
2021-01-20 14:11:08 -06:00
parent fb37473e72
commit 055e0ef9ec
8 changed files with 101 additions and 34 deletions

View File

@@ -7,6 +7,7 @@ import * as pluginapi from "../../typings/pluginapi"
import { version } from "./constants"
import { proxy } from "./proxy"
import * as util from "./util"
import { Router as WsRouter, WebsocketRouter } from "./wsRouter"
const fsp = fs.promises
/**
@@ -21,6 +22,7 @@ require("module")._load = function (request: string, parent: object, isMain: boo
express,
field,
proxy,
WsRouter,
}
}
return originalLoad.apply(this, [request, parent, isMain])
@@ -103,14 +105,16 @@ export class PluginAPI {
}
/**
* mount mounts all plugin routers onto r.
* mount mounts all plugin routers onto r and websocket routers onto wr.
*/
public mount(r: express.Router): void {
public mount(r: express.Router, wr: express.Router): void {
for (const [, p] of this.plugins) {
if (!p.router) {
continue
if (p.router) {
r.use(`${p.routerPath}`, p.router())
}
if (p.wsRouter) {
wr.use(`${p.routerPath}`, (p.wsRouter() as WebsocketRouter).router)
}
r.use(`${p.routerPath}`, p.router())
}
}