Files
mcs-lose/backend/server.js
theis.gaedigk 0a2f1e650d Enhance backend and frontend setup with MySQL integration, Docker configurations, and toast notifications
- Updated .gitignore to include additional environment and build files
- Configured Dockerfiles for backend and frontend with npm install and port exposure
- Added MySQL connection pool and query function in backend services
- Implemented form submission with toast notifications in MainForm component
- Updated package.json and package-lock.json for new dependencies
- Enhanced routing and layout in frontend with toast notifications
2025-08-11 19:56:43 +02:00

37 lines
878 B
JavaScript

import express from "express";
import cors from "cors";
import env from "dotenv";
import { query } from "./services/database.js";
env.config();
const app = express();
const port = 8002;
app.use(cors());
app.use(express.urlencoded({ extended: true }));
app.set("view engine", "ejs");
app.use(express.json());
app.get("/", (req, res) => {
res.render("index.ejs", { title: port });
});
app.post("/lose", async (req, res) => {
const result = await query(req.body);
if (result.success) {
res.status(200).send("Update successful");
} else {
res.status(400).send("Update failed");
}
});
app.listen(port, () => {
console.log(`Server is running on port: ${port}`);
});
// error handling code
app.use((err, req, res, next) => {
// Log the error stack and send a generic error response
console.error(err.stack);
res.status(500).send("Something broke!");
});