initial ws setup

This commit is contained in:
2026-02-05 20:45:38 -05:00
parent 9eb19b0b9a
commit 9f5ec4fff2
5 changed files with 75 additions and 20 deletions

View File

@@ -1,22 +1,34 @@
import express from 'express'
import express from "express";
import http from "http";
// routes
import { matchRouter } from './routes/matches.route.js'
import { matchRouter } from "./routes/matches.route.js";
import { attachWebsocketServer } from "./ws/server.js";
const app = express()
const PORT = process.env.PORT || 8081;
const HOST = process.env.HOST || "0.0.0.0";
const port = process.env.PORT || 8081
const app = express();
app.use(express.json())
const server = http.createServer(app);
app.get('/',(_,res)=>{
res.send('Hello from express server!')
})
app.use(express.json());
app.use('/matches', matchRouter)
app.get("/", (_, res) => {
res.send("Hello from express server!");
});
app.listen(port, ()=>{
console.info(`Listening on port ${port}`)
})
app.use("/matches", matchRouter);
const { broadcastMatchCreated } = attachWebsocketServer(server);
app.locals.broadcastMatchCreated = broadcastMatchCreated;
server.listen(PORT, HOST, () => {
const baseURL =
HOST === "0.0.0.0" ? `http://localhost:${PORT}` : `http://${HOST}:${PORT}`;
console.info(`Server running on ${baseURL}`);
console.info(
`Websocket server running on ${baseURL.replace("http", "ws")}/ws`,
);
});