diff --git a/Dockerfile b/Dockerfile index 79e9bf1..a901622 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,4 +14,6 @@ COPY dist dist EXPOSE 3000 +ENV SERVE_WEB=false + CMD ["npm", "run", "serve"] diff --git a/server.ts b/server.ts index 15c2189..0c99d15 100644 --- a/server.ts +++ b/server.ts @@ -22,6 +22,7 @@ import cors from "cors"; const DB_FOLDER = path.join(process.cwd(), "volume", "db"); const WEB_FOLDER = path.join(process.cwd(), "web", "public"); +const SERVE_WEB = process.env.SERVE_WEB != "false"; const VERSIONS = ["v1", "v2", "v3"]; const PORT = process.env.PORT || 3000; @@ -41,7 +42,7 @@ app.get('/', async (req: Request, res: Response) => { const userAgent = req.headers['user-agent'] || ''; const isBrowser = /Mozilla|Chrome|Firefox|Safari|Edg/.test(userAgent); - if (isBrowser) { + if (isBrowser && SERVE_WEB) { res.sendFile(path.join(WEB_FOLDER, "index.html")); } else { const dataStr = await fs.readFile(path.join(DB_FOLDER, "v1.json"), "utf8"); @@ -53,15 +54,6 @@ app.get('/', async (req: Request, res: Response) => { } }); -app.get('/versioned/v1', async (_: Request, res: Response) => { - const dataStr = await fs.readFile(path.join(DB_FOLDER, "v1.json"), "utf8"); - const data = JSON.parse(dataStr); - - data["status"]["currentUpdateSchedule"] = getCurrentInterval(); - - res.json(data); -}); - VERSIONS.forEach((version) => { app.get(`/versioned/${version}`, async (_: Request, res: Response) => { try { @@ -128,10 +120,12 @@ app.post("/report", async (req: Request, res: Response): Promise => { res.status(200).json({ message: "Report received successfully." }); }); -app.use(express.static(path.join(process.cwd(), 'web/public'), { - index: 'index.html', - extensions: ['html'], -})); +if (SERVE_WEB) { + app.use(express.static(path.join(process.cwd(), 'web/public'), { + index: 'index.html', + extensions: ['html'], + })); +} app.listen(PORT, () => { console.log(`Server is running at http://localhost:${PORT}`);