fix: extract createBunWebSocket to avoid circular import
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,8 +2,8 @@ import { env } from "@haushaltsApp/env/server";
|
|||||||
import { Hono } from "hono";
|
import { Hono } from "hono";
|
||||||
import { cors } from "hono/cors";
|
import { cors } from "hono/cors";
|
||||||
import { logger } from "hono/logger";
|
import { logger } from "hono/logger";
|
||||||
|
import { injectWebSocket } from "./ws/bun-ws";
|
||||||
import { registerRoutes } from "./routes";
|
import { registerRoutes } from "./routes";
|
||||||
import { injectWebSocket } from "./ws/shopping-ws";
|
|
||||||
|
|
||||||
const app = new Hono();
|
const app = new Hono();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ import type { ShoppingServerEvent } from "@haushaltsApp/shared/schemas/shopping.
|
|||||||
import { addShoppingItemSchema } from "@haushaltsApp/shared/schemas/shopping.schema";
|
import { addShoppingItemSchema } from "@haushaltsApp/shared/schemas/shopping.schema";
|
||||||
import { authMiddleware, requireAuth, type AuthVariables } from "../middleware/auth.middleware";
|
import { authMiddleware, requireAuth, type AuthVariables } from "../middleware/auth.middleware";
|
||||||
import { tenantMiddleware, requireHousehold, type TenantVariables } from "../middleware/tenant.middleware";
|
import { tenantMiddleware, requireHousehold, type TenantVariables } from "../middleware/tenant.middleware";
|
||||||
import { broadcast, upgradeWebSocket, createShoppingWsHandler } from "../ws/shopping-ws";
|
import { broadcast, createShoppingWsHandler } from "../ws/shopping-ws";
|
||||||
|
import { upgradeWebSocket } from "../ws/bun-ws";
|
||||||
import {
|
import {
|
||||||
getShoppingItems,
|
getShoppingItems,
|
||||||
addShoppingItem,
|
addShoppingItem,
|
||||||
|
|||||||
3
apps/server/src/ws/bun-ws.ts
Normal file
3
apps/server/src/ws/bun-ws.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import { createBunWebSocket } from "hono/bun";
|
||||||
|
|
||||||
|
export const { upgradeWebSocket, injectWebSocket } = createBunWebSocket();
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
import { db, eq, and, isNotNull } from "@haushaltsApp/db";
|
import { db, eq, and, isNotNull } from "@haushaltsApp/db";
|
||||||
import { shoppingItems } from "@haushaltsApp/db/schema";
|
import { shoppingItems } from "@haushaltsApp/db/schema";
|
||||||
import { createBunWebSocket } from "hono/bun";
|
|
||||||
import type { WSContext } from "hono/ws";
|
import type { WSContext } from "hono/ws";
|
||||||
import type { ShoppingServerEvent, ShoppingClientCommand } from "@haushaltsApp/shared/schemas/shopping.schema";
|
import type { ShoppingServerEvent, ShoppingClientCommand } from "@haushaltsApp/shared/schemas/shopping.schema";
|
||||||
import {
|
import {
|
||||||
@@ -10,11 +9,10 @@ import {
|
|||||||
uncheckShoppingItem,
|
uncheckShoppingItem,
|
||||||
deleteShoppingItem,
|
deleteShoppingItem,
|
||||||
} from "../services/shopping.service";
|
} from "../services/shopping.service";
|
||||||
|
export { upgradeWebSocket } from "./bun-ws";
|
||||||
|
|
||||||
type WsData = { householdId: string; userId: string };
|
type WsData = { householdId: string; userId: string };
|
||||||
|
|
||||||
export const { upgradeWebSocket, injectWebSocket } = createBunWebSocket<WsData>();
|
|
||||||
|
|
||||||
// ── Room Management ────────────────────────────────────────────────────────────
|
// ── Room Management ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
const rooms = new Map<string, Set<WSContext<WsData>>>();
|
const rooms = new Map<string, Set<WSContext<WsData>>>();
|
||||||
|
|||||||
Reference in New Issue
Block a user