Add timetable, substitutions and history API

This commit is contained in:
2022-05-01 23:23:20 +02:00
parent 0fbcd02169
commit a47d913d6f
2 changed files with 138 additions and 5 deletions

View File

@ -1,15 +1,19 @@
import express from "express";
import Prisma from "@prisma/client";
import { getTimetable, getSubstitutions, getHistory } from "./api/index.js";
const app = express();
const prisma = new Prisma.PrismaClient();
const port = process.send.PORT || 3000;
app.get("/", async (_req, res) => {
const result = await prisma.substitution.findMany();
res.send(result);
app.get("/api/timetable", getTimetable);
app.get("/api/substitutions", getSubstitutions);
app.get("/api/history", getHistory);
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}`);
});