add: merged front with back
This commit is contained in:
parent
1832ed12ec
commit
48f50a1daa
42 changed files with 5458 additions and 20 deletions
36
index.js
36
index.js
|
@ -1,36 +0,0 @@
|
|||
const express = require("express");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const cookieParser = require("cookie-parser");
|
||||
const cors = require("cors");
|
||||
require("dotenv").config();
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(express.json());
|
||||
app.use(cookieParser());
|
||||
app.use(cors({
|
||||
origin: ["https://joclud.leizour.fr", "http://localhost:5173"],
|
||||
methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
|
||||
allowedHeaders: ["Content-Type", "Authorization"]
|
||||
}));
|
||||
|
||||
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.listen(80, () => {
|
||||
console.log(`Server listening on http://localhost:80/`);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue