39 lines
957 B
JavaScript
39 lines
957 B
JavaScript
import express from "express";
|
|
import {
|
|
getTimetable,
|
|
getSubstitutions,
|
|
getHistory,
|
|
getClasses,
|
|
} from "./api/index.js";
|
|
import { Parser } from "./parser/index.js";
|
|
import cors from "cors";
|
|
|
|
const app = express();
|
|
const port = process.env.PORT || 3000;
|
|
app.use(cors());
|
|
|
|
if (!process.env.DSB_USER || !process.env.DSB_PASSWORD) {
|
|
console.error("Error: DSB Auth environment variables missing!");
|
|
process.exit(1);
|
|
}
|
|
const parser = new Parser(
|
|
process.env.DSB_USER,
|
|
process.env.DSB_PASSWORD,
|
|
process.env.UPDATE_INTERVAL || 1 * 60 * 1000
|
|
);
|
|
|
|
app.get("/api/timetable", getTimetable);
|
|
app.get("/api/substitutions", getSubstitutions);
|
|
app.get("/api/history", getHistory);
|
|
app.get("/api/classes", getClasses);
|
|
app.get("/api/*", (req, res) => {
|
|
res.sendStatus(400);
|
|
});
|
|
|
|
app.use("/", express.static("../dist"));
|
|
app.use("/*", express.static("../dist"));
|
|
|
|
app.listen(port, () => {
|
|
console.log(`Server listening on http://localhost:${port}`);
|
|
});
|