40 lines
1.0 KiB
JavaScript
40 lines
1.0 KiB
JavaScript
import express from "express";
|
|
import http from "http";
|
|
|
|
// routes
|
|
import { matchRouter } from "./routes/matches.route.js";
|
|
import { attachWebsocketServer } from "./ws/server.js";
|
|
import { securityMiddleware } from "./utils/arkjet.js";
|
|
import { comRouter } from "./routes/commentary.route.js";
|
|
|
|
const PORT = process.env.PORT || 8081;
|
|
const HOST = process.env.HOST || "0.0.0.0";
|
|
|
|
const app = express();
|
|
|
|
const server = http.createServer(app);
|
|
|
|
app.use(express.json());
|
|
|
|
app.get("/", (_, res) => {
|
|
res.send("Hello from express server!");
|
|
});
|
|
|
|
// middleware
|
|
app.use(securityMiddleware());
|
|
|
|
app.use("/matches", matchRouter);
|
|
app.use("/matches/:id/commentary", comRouter);
|
|
|
|
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`,
|
|
);
|
|
});
|