diff --git a/desktop/flipper-server-core/src/comms/ServerWebSocket.tsx b/desktop/flipper-server-core/src/comms/ServerWebSocket.tsx index aecd0c0fa..bf639a30a 100644 --- a/desktop/flipper-server-core/src/comms/ServerWebSocket.tsx +++ b/desktop/flipper-server-core/src/comms/ServerWebSocket.tsx @@ -35,6 +35,10 @@ export interface ConnectionCtx { request: IncomingMessage; } +// based on https://github.com/websockets/ws/blob/master/lib/websocket-server.js#L40, +// exposed to share with socket.io defaults +export const WEBSOCKET_MAX_MESSAGE_SIZE = 100 * 1024 * 1024; + /** * It serves as a base class for WebSocket based servers. It delegates the 'connection' * event to subclasses as a customisation point. @@ -52,6 +56,7 @@ class ServerWebSocket extends ServerAdapter { const wsServer = new WSServer({ server, verifyClient: this.verifyClient(), + maxPayload: WEBSOCKET_MAX_MESSAGE_SIZE, }); // We do not need to listen to http server's `error` because it is propagated to WS diff --git a/desktop/flipper-server-core/src/index.tsx b/desktop/flipper-server-core/src/index.tsx index f1a81d70b..f5732302b 100644 --- a/desktop/flipper-server-core/src/index.tsx +++ b/desktop/flipper-server-core/src/index.tsx @@ -26,3 +26,5 @@ export function getGatekeepers(username: string): Record { } return GKImplementation.allGKs(); } + +export {WEBSOCKET_MAX_MESSAGE_SIZE} from './comms/ServerWebSocket'; diff --git a/desktop/flipper-server/src/startBaseServer.tsx b/desktop/flipper-server/src/startBaseServer.tsx index c3beef23f..666128947 100644 --- a/desktop/flipper-server/src/startBaseServer.tsx +++ b/desktop/flipper-server/src/startBaseServer.tsx @@ -12,6 +12,7 @@ import http from 'http'; import path from 'path'; import fs from 'fs-extra'; import socketio from 'socket.io'; +import {WEBSOCKET_MAX_MESSAGE_SIZE} from 'flipper-server-core'; type Config = { port: number; @@ -61,6 +62,8 @@ function startAssetServer( } function addWebsocket(server: http.Server) { - const io = new socketio.Server(server); + const io = new socketio.Server(server, { + maxHttpBufferSize: WEBSOCKET_MAX_MESSAGE_SIZE, + }); return io; } diff --git a/desktop/scripts/start-flipper-server.ts b/desktop/scripts/start-flipper-server.ts index e983e783b..dc52d1eaf 100644 --- a/desktop/scripts/start-flipper-server.ts +++ b/desktop/scripts/start-flipper-server.ts @@ -138,7 +138,10 @@ function launchServer() { } async function restartServer() { - proc?.kill(9); + if (proc) { + proc.kill(9); + await sleep(1000); + } try { await compileServerMain(); await launchServer(); @@ -196,10 +199,13 @@ async function startWatchChanges() { await restartServer(); if (argv.open) { - setTimeout(() => { - // TODO: make port configurable together with flipper-server - open('http://localhost:52342/index.web.dev.html'); - }, 2000); + await sleep(2000); + // TODO: make port configurable together with flipper-server + open('http://localhost:52342/index.web.dev.html'); } } })(); + +function sleep(ms: number) { + return new Promise((r) => setTimeout(r, ms)); +}