File size: 1,692 Bytes
635a8a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"use strict";
const express = require("express");
const path = require("path");
const db = require("./db");

const app = express();
const PORT = process.env.PORT || 7860;

app.use(express.json());
app.use(express.static(__dirname)); // Serve static files (html, css, js)

// API: Get all rosters
app.get("/api/roster", (req, res) => {
  try {
    const data = db.getRosters();
    res.json(data);
  } catch (err) {
    console.error("[WEB] Error fetching roster:", err.message);
    res.status(500).json({ error: "Failed to fetch roster" });
  }
});

// API: Add roster (optional, mainly used by web UI if needed)
app.post("/api/roster", (req, res) => {
  const { team, user, role } = req.body;
  if (!team || !user || !role) {
    return res.status(400).json({ error: "Missing team, user, or role" });
  }
  try {
    db.addRoster(team, user, role);
    res.json({ success: true });
  } catch (err) {
    console.error("[WEB] Error adding roster:", err.message);
    res.status(500).json({ error: "Failed to add roster" });
  }
});

// Serve Dashboard
app.get("/", (req, res) => {
  res.sendFile(path.resolve(__dirname, "dashboard.html"));
});

// Serve League Page
app.get("/league", (req, res) => {
  res.sendFile(path.resolve(__dirname, "league.html"));
});

// Serve Roster Page
app.get("/roster", (req, res) => {
  res.sendFile(path.resolve(__dirname, "roster.html"));
});

app.listen(PORT, "0.0.0.0", () => {
  console.log(`[WEB] Server running on port ${PORT}`);
  console.log(`[WEB] Dashboard: http://localhost:${PORT}/`);
  console.log(`[WEB] League:    http://localhost:${PORT}/league`);
  console.log(`[WEB] Roster:    http://localhost:${PORT}/roster`);
});

module.exports = app;