feat: full health & fitness app with workout/meal planning
- Login/register with JWT auth - User profile (age, weight, height, goal, country) - AI trainer agent: 7-day workout programs by goal - AI dietitian agent: calorie-based meal plans with Turkish cuisine - Shopping list generator from meal plans - Modern Turkish UI (SPA) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
"use strict";
|
||||
|
||||
const express = require("express");
|
||||
const path = require("path");
|
||||
const { getDb } = require("./database");
|
||||
|
||||
const authRoutes = require("./routes/auth");
|
||||
const profileRoutes = require("./routes/profile");
|
||||
const programRoutes = require("./routes/program");
|
||||
|
||||
const app = express();
|
||||
const PORT = parseInt(process.env.PORT, 10) || 3000;
|
||||
@@ -8,14 +14,17 @@ const startTime = Date.now();
|
||||
|
||||
app.disable("x-powered-by");
|
||||
|
||||
app.get("/", (_req, res) => {
|
||||
res.json({
|
||||
service: "health-app",
|
||||
version: process.env.APP_VERSION || "1.0.0",
|
||||
environment: process.env.NODE_ENV || "development",
|
||||
});
|
||||
});
|
||||
// Body parsing
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
|
||||
// Static files
|
||||
app.use(express.static(path.join(__dirname, "public")));
|
||||
|
||||
// Initialize database on startup
|
||||
getDb();
|
||||
|
||||
// Health & readiness probes (Kubernetes)
|
||||
app.get("/health", (_req, res) => {
|
||||
res.json({
|
||||
status: "healthy",
|
||||
@@ -26,16 +35,36 @@ app.get("/health", (_req, res) => {
|
||||
});
|
||||
|
||||
app.get("/ready", (_req, res) => {
|
||||
res.json({ ready: true });
|
||||
try {
|
||||
getDb();
|
||||
res.json({ ready: true });
|
||||
} catch (err) {
|
||||
res.status(503).json({ ready: false, error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
app.use((_req, res) => {
|
||||
res.status(404).json({ error: "Not Found" });
|
||||
// API routes
|
||||
app.use("/api/auth", authRoutes);
|
||||
app.use("/api/profile", profileRoutes);
|
||||
app.use("/api/program", programRoutes);
|
||||
|
||||
// SPA fallback - serve index.html for non-API routes
|
||||
app.get("*", (req, res) => {
|
||||
if (req.path.startsWith("/api/")) {
|
||||
return res.status(404).json({ error: "API endpoint bulunamadı" });
|
||||
}
|
||||
res.sendFile(path.join(__dirname, "public", "index.html"));
|
||||
});
|
||||
|
||||
// 404 handler for API
|
||||
app.use((req, res) => {
|
||||
res.status(404).json({ error: "Bulunamadı" });
|
||||
});
|
||||
|
||||
// Error handler
|
||||
app.use((err, _req, res, _next) => {
|
||||
console.error("Unhandled error:", err.message);
|
||||
res.status(500).json({ error: "Internal Server Error" });
|
||||
res.status(500).json({ error: "Sunucu hatası" });
|
||||
});
|
||||
|
||||
const server = app.listen(PORT, "0.0.0.0", () => {
|
||||
|
||||
Reference in New Issue
Block a user