import { type Durable as _Durable, _createDurable } from "./durableFramework"; type _Env = Record; //this will be replaced with durable objects imports //@ts-expect-error __RESOCKET_IMPORT_DURABLE__; const _durables: Record = {}; //we add the workers to _durables here //@ts-expect-error __RESOCKET_ADD_AND_EXPORT_DURABLE__; //hack to prevent esbuild from removing the import const __keepVariable = (v: any) => {}; __keepVariable(_createDurable); async function _handleApiRequest(request: Request, env: _Env) { let { searchParams } = new URL(request.url); //this is the durable object name const room = searchParams.get("room"); //this is the id of the room to join const roomId = searchParams.get("roomId"); if (!room || !roomId) { return new Response("Invalid Parameters!", { status: 400 }); } const durableRoom = env[room] as DurableObjectNamespace | undefined; const durableRoomUserWorker = _durables[room]; if (!durableRoom || !durableRoomUserWorker) return new Response("No Room Found!", { status: 404 }); //here we want to do some sort of onBeforeConnect shit await durableRoomUserWorker.onBeforeConnect?.(request); return durableRoom .get(durableRoom.idFromName(roomId)) .fetch(request.url, request); } export default { async fetch(request: Request, env: _Env, ctx: ExecutionContext) { return await _handleApiRequest(request, env); }, };