-ต้นแบบ โครงสร้าง ไฟล์ API เส้น /api/ttc

This commit is contained in:
2025-11-17 09:03:36 +07:00
parent eefbb8e5dd
commit 9f9c9aa80d
25 changed files with 1019 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
import express from 'express'
import cors from 'cors'
import dotenv from 'dotenv'
import router from './routes/route.js'
import { globalResponseHandler } from './middlewares/responseHandler.js'
dotenv.config()
const app = express()
app.use(cors())
app.use(express.json({ limit: '10mb' }))
app.use(globalResponseHandler);
app.use((err, req, res, next) => {
if (err instanceof SyntaxError && err.status === 400 && 'body' in err) {
console.error('🟥 Invalid JSON Received:', err.message)
return res.status(400).json({
code: "400",
message: "Invalid JSON format",
message_th: "โครงสร้าง JSON ไม่ถูกต้อง",
data: []
})
}
next()
})
app.use('/api/ttc', router)
app.listen(process.env.PORT, () => {
console.log(`${process.env.PJ_NAME} running on port ${process.env.PORT}`)
})