add: merged front with back
This commit is contained in:
parent
1832ed12ec
commit
48f50a1daa
42 changed files with 5458 additions and 20 deletions
32
back/index.js
Normal file
32
back/index.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
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());
|
||||
|
||||
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(3000, () => {
|
||||
console.log(`Server listening on http://localhost:3000/`);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue