const HttpLive = Effect.gen(function* () {
const config = yield* ServerConfig;
yield* Effect.log("Starting server with WebSocket support at /ws");
// Initialize presence service
const presence = yield* makePresenceService;
// Get the runtime for running Effects from WebSocket handlers
const runtime = yield* Effect.runtime<never>();
const AllRouters = Layer.mergeAll(ApiRouter, RpcRouter);
// Create Bun WebSocket server on a separate port
Bun.serve<WebSocketConnectionData>({
port: config.port + 1; // WebSocket on port 9001,
hostname: config.hostname,
fetch: ()=>{}, // handle scope and upgrade
websocket: {} // all the ws magic 🪄
});
yield* Effect.log(
`Bun WebSocket server running on ws://${config.hostname}:${wsPort}/ws`,
);
return HttpLayerRouter.serve(AllRouters).pipe(
HttpServer.withLogAddress,
Layer.provide(DevTools.layer()),
Layer.provideMerge(BunHttpServer.layerConfig(ServerConfig)),
);
}).pipe(Layer.unwrapEffect, Layer.launch);
const HttpLive = Effect.gen(function* () {
const config = yield* ServerConfig;
yield* Effect.log("Starting server with WebSocket support at /ws");
// Initialize presence service
const presence = yield* makePresenceService;
// Get the runtime for running Effects from WebSocket handlers
const runtime = yield* Effect.runtime<never>();
const AllRouters = Layer.mergeAll(ApiRouter, RpcRouter);
// Create Bun WebSocket server on a separate port
Bun.serve<WebSocketConnectionData>({
port: config.port + 1; // WebSocket on port 9001,
hostname: config.hostname,
fetch: ()=>{}, // handle scope and upgrade
websocket: {} // all the ws magic 🪄
});
yield* Effect.log(
`Bun WebSocket server running on ws://${config.hostname}:${wsPort}/ws`,
);
return HttpLayerRouter.serve(AllRouters).pipe(
HttpServer.withLogAddress,
Layer.provide(DevTools.layer()),
Layer.provideMerge(BunHttpServer.layerConfig(ServerConfig)),
);
}).pipe(Layer.unwrapEffect, Layer.launch);