Add basic auth functionality

This commit is contained in:
2022-05-04 01:38:25 +02:00
parent 856e514da7
commit 6261dbb04c
5 changed files with 147 additions and 0 deletions

View File

@ -5,12 +5,18 @@ import {
getHistory,
getClasses,
} from "./api/index.js";
import { Auth } from "./api/auth.js";
import { Parser } from "./parser/index.js";
import cors from "cors";
import cookieParser from "cookie-parser";
const app = express();
const port = process.env.PORT || 3000;
app.use(cors());
app.use(cookieParser());
app.use(express.urlencoded({ extended: true }));
const auth = new Auth();
if (!process.env.DSB_USER || !process.env.DSB_PASSWORD) {
console.error("Error: DSB Auth environment variables missing!");
@ -22,6 +28,9 @@ const parser = new Parser(
process.env.UPDATE_INTERVAL || 1 * 60 * 1000
);
app.post("/login", auth.login);
app.use(auth.checkLogin);
app.get("/api/timetable", getTimetable);
app.get("/api/substitutions", getSubstitutions);
app.get("/api/history", getHistory);