initial ws setup
This commit is contained in:
36
src/index.js
36
src/index.js
@@ -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`,
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user