Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit c2cc25ec authored by 65160024's avatar 65160024
Browse files

update server.js

parent 320c58d0
Branches
No related tags found
No related merge requests found
......@@ -4,9 +4,9 @@ const app = express();
const morgan = require("morgan");
const { readdirSync } = require("fs");
const cors = require("cors");
// const authRouter = require('./routes/auth');
// const categoryRouter = require('./routes/category');
const path = require("path");
// เชื่อมต่อฐานข้อมูล MySQL
const db = mysql.createConnection({
host: "node77730-project-65160024.th2.melon.cloud",
port: "11818",
......@@ -15,22 +15,21 @@ const db = mysql.createConnection({
database: "borrow_project",
});
//middleware
// Middleware
app.use(morgan("dev"));
app.use(express.json({ limit: "20mb" }));
// การตั้งค่า CORS
app.use(cors());
// app.use('/api', authRouter)
// app.use('/api', categoryRouter)
const path = require("path");
readdirSync(path.join(__dirname, "routes")).map((c) =>
app.use("/api", require(path.join(__dirname, "routes", c)))
);
// โหลด router จากโฟลเดอร์ routes
const routesPath = path.join(__dirname, "routes");
readdirSync(routesPath).map((file) => {
const routePath = path.join(routesPath, file);
app.use("/api", require(routePath));
});
app.listen(3000, () => console.log("server is running on port 3000"));
app.listen(3000, () => console.log("Server is running on port 3000"));
// เชื่อมต่อกับฐานข้อมูล
db.connect((err) => {
if (err) {
console.error("❌ ไม่สามารถเชื่อมต่อฐานข้อมูล:", err);
......@@ -38,4 +37,3 @@ db.connect((err) => {
}
console.log("✅ เชื่อมต่อฐานข้อมูลสำเร็จ!");
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment