1
0

feat: Serve web
All checks were successful
Remote Deploy / deploy (push) Successful in 10s

This commit is contained in:
2026-02-11 11:25:03 +01:00
parent 16b8b9ae10
commit 7938d2cb9f
2 changed files with 10 additions and 14 deletions

View File

@@ -14,4 +14,6 @@ COPY dist dist
EXPOSE 3000
ENV SERVE_WEB=false
CMD ["npm", "run", "serve"]

View File

@@ -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<any> => {
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}`);