From 8bf1c3432efd79fe149f32a58143e380614f59c6 Mon Sep 17 00:00:00 2001 From: sacha Date: Mon, 5 Feb 2024 11:06:35 +1100 Subject: [PATCH] Fix startup with no data (#143) --- api/src/server.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/api/src/server.ts b/api/src/server.ts index 26133bf0..dbf20f0f 100644 --- a/api/src/server.ts +++ b/api/src/server.ts @@ -2,6 +2,8 @@ import express from "express"; import cors from "cors"; import * as Sentry from "@sentry/node"; import * as Tracing from "@sentry/tracing"; +import fs from "fs"; +import { dataLocation } from "./load-data" import * as notangles from "./notangles/index"; import * as freerooms from "./freerooms/index"; @@ -43,6 +45,15 @@ app.use((err, req, res, next) => { res.end(res.sentry + "\n"); }); +if(!fs.existsSync(dataLocation)) { + fs.writeFile(dataLocation, JSON.stringify({ + timetableData: {}, + courseWarnings: [], + lastUpdated: 0, + })); +} + + app.listen(port, () => { console.log(`App is running at http://localhost:${port}.`); console.log("Press ctrl-c to stop.");