**Problem:** - player-ownership.ts imported drizzle-orm and @/db at top level - When RoomMemoryPairsProvider imported client-safe utilities, Webpack bundled ALL imports including database code - This caused hydration error: "The 'original' argument must be of type Function" - Node.js util.promisify was being called in browser context **Solution:** 1. Created player-ownership.client.ts with ONLY client-safe utilities - No database imports - Safe to import from 'use client' components - Contains: buildPlayerOwnershipFromRoomData(), buildPlayerMetadata(), helper functions 2. Updated player-ownership.ts to re-export client utilities and add server-only functions - Re-exports everything from .client.ts - Adds buildPlayerOwnershipMap() (async, database-backed) - Safe to import from server components/API routes 3. Updated RoomMemoryPairsProvider to import from .client.ts **Result:** - No more hydration errors on /arcade/room - Client bundle doesn't include database code - Server code can still use both client and server utilities 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
const { createServer } = require("http");
|
|
const { parse } = require("url");
|
|
const next = require("next");
|
|
|
|
const dev = process.env.NODE_ENV !== "production";
|
|
const hostname = "localhost";
|
|
const port = parseInt(process.env.PORT || "3000", 10);
|
|
|
|
const app = next({ dev, hostname, port });
|
|
const handle = app.getRequestHandler();
|
|
|
|
// Run migrations before starting server
|
|
console.log("🔄 Running database migrations...");
|
|
const { migrate } = require("drizzle-orm/better-sqlite3/migrator");
|
|
const { db } = require("./dist/db/index");
|
|
|
|
try {
|
|
migrate(db, { migrationsFolder: "./drizzle" });
|
|
console.log("✅ Migrations complete");
|
|
} catch (error) {
|
|
console.error("❌ Migration failed:", error);
|
|
process.exit(1);
|
|
}
|
|
|
|
app.prepare().then(() => {
|
|
const server = createServer(async (req, res) => {
|
|
try {
|
|
const parsedUrl = parse(req.url, true);
|
|
await handle(req, res, parsedUrl);
|
|
} catch (err) {
|
|
console.error("Error occurred handling", req.url, err);
|
|
res.statusCode = 500;
|
|
res.end("internal server error");
|
|
}
|
|
});
|
|
|
|
// Initialize Socket.IO
|
|
const { initializeSocketServer } = require("./dist/socket-server");
|
|
initializeSocketServer(server);
|
|
|
|
server
|
|
.once("error", (err) => {
|
|
console.error(err);
|
|
process.exit(1);
|
|
})
|
|
.listen(port, () => {
|
|
console.log(`> Ready on http://${hostname}:${port}`);
|
|
});
|
|
});
|