Provide WsRouter to plugins
This commit is contained in:
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user