aboutsummaryrefslogtreecommitdiffstats
path: root/backend/ts/index.ts
blob: e4ec5eeac6c8b285f4ff3d9b1ac2cc15bb910962 (plain) (blame)
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
import express from "express";
import session from "express-session";
import * as dotenv from "dotenv";

import login from "./api/login";
import startPoint from "./api/startPoint";
import readyStateToggle from "./api/readyStateToggle";
import getCurrentGameState from "./api/getCurrentGameState";
import saveGameBoard from "./api/saveGameBoard";

export const global = { stop: false };

dotenv.config();
const app = express();
const PORT = 8000;

if (!process.env.SESSION_KEY)
  throw Error("SESSION_KEY is undefined");

app.use(session({ secret: process.env.SESSION_KEY, cookie: { maxAge: 60000 } }));
app.use(express.json());
app.use("/", express.static("./public"));

app.get("/favicon.ico", (req, res) => res.redirect("https://lukesmith.xyz/favicon.ico"));

app.get("/startPoint", startPoint)

app.post("/login", login);
app.post("/readyStateToggle", readyStateToggle);
app.post("/getCurrentGameState", getCurrentGameState);
app.post("/saveGameBoard", saveGameBoard);


app.listen(PORT, () => {
  console.log(`[server]: Server is running at https://localhost:${PORT}`);
});