Refactor server websocket dependency tree to fix jest tests
This commit is contained in:
parent
3d57010a10
commit
00cbf6cf37
|
@ -10,7 +10,7 @@ import {
|
||||||
} from "@budibase/backend-core/objectStore"
|
} from "@budibase/backend-core/objectStore"
|
||||||
import { PluginType, FileType, PluginSource } from "@budibase/types"
|
import { PluginType, FileType, PluginSource } from "@budibase/types"
|
||||||
import env from "../../../environment"
|
import env from "../../../environment"
|
||||||
import { ClientAppSocket } from "../../../app"
|
import { ClientAppSocket } from "../../../websocket"
|
||||||
|
|
||||||
export async function getPlugins(type?: PluginType) {
|
export async function getPlugins(type?: PluginType) {
|
||||||
const db = getGlobalDB()
|
const db = getGlobalDB()
|
||||||
|
|
|
@ -32,7 +32,7 @@ import * as migrations from "./migrations"
|
||||||
import { events, installation, tenancy } from "@budibase/backend-core"
|
import { events, installation, tenancy } from "@budibase/backend-core"
|
||||||
import { createAdminUser, getChecklist } from "./utilities/workerRequests"
|
import { createAdminUser, getChecklist } from "./utilities/workerRequests"
|
||||||
import { watch } from "./watch"
|
import { watch } from "./watch"
|
||||||
import { Websocket } from "./websocket"
|
import { initialise as initialiseWebsockets } from "./websocket"
|
||||||
|
|
||||||
const app = new Koa()
|
const app = new Koa()
|
||||||
|
|
||||||
|
@ -77,9 +77,7 @@ if (env.isProd()) {
|
||||||
|
|
||||||
const server = http.createServer(app.callback())
|
const server = http.createServer(app.callback())
|
||||||
destroyable(server)
|
destroyable(server)
|
||||||
|
initialiseWebsockets(server)
|
||||||
// initialise websockets
|
|
||||||
export const ClientAppSocket = new Websocket(server, "/socket/client")
|
|
||||||
|
|
||||||
let shuttingDown = false,
|
let shuttingDown = false,
|
||||||
errCode = 0
|
errCode = 0
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Server } from "socket.io"
|
import { Server } from "socket.io"
|
||||||
import http from "http"
|
import http from "http"
|
||||||
|
|
||||||
export class Websocket {
|
class Websocket {
|
||||||
socketServer: Server
|
socketServer: Server
|
||||||
|
|
||||||
constructor(server: http.Server, path: string) {
|
constructor(server: http.Server, path: string) {
|
||||||
|
@ -15,3 +15,12 @@ export class Websocket {
|
||||||
this.socketServer.sockets.emit(event, payload)
|
this.socketServer.sockets.emit(event, payload)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Likely to be more socket instances in future
|
||||||
|
let ClientAppSocket: Websocket
|
||||||
|
|
||||||
|
export const initialise = (server: http.Server) => {
|
||||||
|
ClientAppSocket = new Websocket(server, "/socket/client")
|
||||||
|
}
|
||||||
|
|
||||||
|
export { ClientAppSocket }
|
||||||
|
|
Loading…
Reference in New Issue