aboutsummaryrefslogtreecommitdiff
path: root/app.js
blob: fcb7a8a1b729c33b6464f5f4d966860b91637d2d (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
37
require("dotenv").config();
const express = require("express");
const session = require("express-session");

const { auth, checkUser } = require("./auth");
const motto = require("./motto");
const mottovote = require("./mottovote");
const quotes = require("./quotes");
const poll = require("./poll");

const app = express();

// TODO: Use secure: true in production
const redis = require("redis");
const RedisStore = require("connect-redis")(session);
const redisClient = redis.createClient();
app.use(
    session({
        store: new RedisStore({ client: redisClient }),
        secret: process.env.sessionSecret,
        resave: false,
        saveUninitialized: true,
        cookie: { secure: false },
    }),
);

app.use(express.urlencoded({ extended: true }));
app.use(express.json());

app.use("/", express.static(__dirname + "/overview/public"));
app.use("/motto", checkUser, motto);
app.use("/mottovote", checkUser, mottovote);
app.use("/quotes", checkUser, quotes);
app.use("/poll", checkUser, poll);
app.use("/auth", auth);

app.listen(5005, () => console.log("Server started on http://localhost:5005"));