feat: add backend Express server with API and static serving

This commit is contained in:
2026-03-07 22:59:13 -06:00
parent a2e0ba405b
commit 02d69fa491

26
backend/src/index.ts Normal file
View File

@@ -0,0 +1,26 @@
import express from "express";
import cors from "cors";
import path from "path";
import imageRoutes from "./routes/image";
const app = express();
const port = process.env.PORT || 3000;
app.use(cors());
app.use(express.json());
// API routes
app.use("/api", imageRoutes);
// Serve frontend static build
const publicDir = path.join(__dirname, "public");
app.use(express.static(publicDir));
// Fallback to index.html for SPA routing
app.get("*", (_req, res) => {
res.sendFile(path.join(publicDir, "index.html"));
});
app.listen(port, () => {
console.log(`Server listening on port ${port}`);
});