clove/system
src/worker.ts
/* src/worker.ts
* Copyright (c) 2026 Clove Nytrix Doughmination Twilight
* Licensed under the DASL-1.2 Licence.
* See LICENCE.md in the project root for full licence information.
*/
// Wraps the SvelteKit build so the Worker can also export the LiveHub Durable Object
// @ts-ignore: generated by `vite build`, so it's missing until the first build
import sveltekit from "../.svelte-kit/cloudflare/_worker.js";
import { LIVE_HUB_NAME, LIVE_SOCKET_PATH } from "./lib/server/plural/config.ts";
import { LiveHub } from "./lib/server/plural/hub.ts";
export { LiveHub };
const kit = sveltekit as unknown as {
fetch(request: Request, env: Cloudflare.Env, ctx: ExecutionContext): Promise<Response>;
};
export default {
fetch(request: Request, env: Cloudflare.Env, ctx: ExecutionContext): Promise<Response> {
if (new URL(request.url).pathname === LIVE_SOCKET_PATH) {
return env.LIVE.get(env.LIVE.idFromName(LIVE_HUB_NAME)).fetch(request);
}
return kit.fetch(request, env, ctx);
},
} satisfies ExportedHandler<Cloudflare.Env>;