Added API endpoints and dockerfile

This commit is contained in:
Lukian 2025-03-24 10:17:37 +01:00
parent 924e55b4f3
commit 5ddad2ed61
31 changed files with 3885 additions and 942 deletions

39
back/index.js Normal file
View file

@ -0,0 +1,39 @@
const express = require("express");
const fs = require("fs");
const path = require("path");
const config = require("./config");
const cookieParser = require("cookie-parser");
const cors = require("cors");
require("dotenv").config();
const app = express();
const port = config.port || 3000;
app.use(express.json());
app.use(cookieParser());
app.use(cors());
function loadRoutes(folderName) {
const routesPath = path.join(__dirname, folderName);
const files = fs.readdirSync(routesPath);
files.forEach((file) => {
if (fs.lstatSync(path.join(routesPath, file)).isDirectory()) {
loadRoutes(`${folderName}/${file}`);
return;
}
const filePath = path.join(routesPath, file);
const route = require(filePath);
app.use(`/${folderName}/${file.split(".")[0]}`, route);
});
}
loadRoutes("api");
app.use(express.static("public"));
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "public", "index.html"));
});
app.listen(port, () => {
console.log(`Server listening on port ${port}`);
});