feat: add backend Express server with API and static serving
This commit is contained in:
26
backend/src/index.ts
Normal file
26
backend/src/index.ts
Normal 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}`);
|
||||
});
|
||||
Reference in New Issue
Block a user