2023-10-07 17:29:53 +07:00
|
|
|
|
/*
|
2025-02-28 11:43:17 +07:00
|
|
|
|
* Report Server
|
|
|
|
|
|
* Web API สำหรับสร้างรายงาน กำหนด Path และเพิ่มฟีเจอร์ได้
|
|
|
|
|
|
* จะใช้ Node.js เป็น reverse proxy ไปหา pandoc ที่ swan ขึ้นมา
|
|
|
|
|
|
* demo frontent อยู่ในโฟลเดอร์ public
|
|
|
|
|
|
*/
|
2023-10-08 18:29:28 +07:00
|
|
|
|
import cors from "cors"
|
2023-10-07 17:29:53 +07:00
|
|
|
|
import swaggerspecs from "./libs/swagger-specs.json"
|
|
|
|
|
|
import swaggerUi from "swagger-ui-express"
|
2025-02-28 11:43:17 +07:00
|
|
|
|
import express, { Express, Request, Response } from "express"
|
|
|
|
|
|
import { docxTemplateRoute } from "./libs/docx-templates-lib"
|
|
|
|
|
|
import { xlsxTemplateRoute } from "./libs/xlsx-template-lib"
|
2025-02-25 19:50:21 +07:00
|
|
|
|
import { htmlTemplateRoute } from "./libs/html-templates-lib"
|
2025-02-28 11:43:17 +07:00
|
|
|
|
import { convertTemplateRoute } from "./libs/convert-libs"
|
2023-10-07 17:29:53 +07:00
|
|
|
|
const app: Express = express()
|
2025-02-28 11:43:17 +07:00
|
|
|
|
const port: number = Number(process.env.PORT) || 80
|
|
|
|
|
|
app.use(cors())
|
|
|
|
|
|
app.use(express.json({ limit: "200mb" })) //‘application/json’
|
|
|
|
|
|
app.use(express.raw({ limit: "200mb" })) //‘application/octet-stream’
|
|
|
|
|
|
app.use(express.urlencoded({ extended: true, limit: "200mb" }))
|
|
|
|
|
|
app.use(
|
|
|
|
|
|
"/swagger",
|
|
|
|
|
|
swaggerUi.serve,
|
|
|
|
|
|
swaggerUi.setup(swaggerspecs, { explorer: true })
|
|
|
|
|
|
)
|
|
|
|
|
|
app.get("/", (req: Request, res: Response) => {
|
2023-10-07 17:29:53 +07:00
|
|
|
|
res.json({
|
2025-02-28 11:43:17 +07:00
|
|
|
|
message: "Hello report-template API !!",
|
2023-10-07 17:29:53 +07:00
|
|
|
|
})
|
|
|
|
|
|
})
|
2025-02-28 11:43:17 +07:00
|
|
|
|
app.use("/api/v1/report-template/docx", docxTemplateRoute)
|
|
|
|
|
|
app.use("/api/v1/report-template/xlsx", xlsxTemplateRoute)
|
|
|
|
|
|
app.use("/api/v1/report-template/html", htmlTemplateRoute)
|
|
|
|
|
|
app.use("/api/v1/report-template/convert", convertTemplateRoute)
|
|
|
|
|
|
app.listen(port, () => console.log(`Application is running on port ${port}`))
|