Skip to content

vtrc-ocr-api — Endpoint Catalog

บทนี้ (branch: main) เอกสาร ทุก HTTP surface ที่ process เปิดรับ — รวม static, Swagger, health, OCR, และ 404/error

Global middleware ทุก request (ยกเว้นก่อน mount ตามลำดับใน app.js):

  1. helmet()app.js:15
  2. cors() — ไม่มี origin allowlist — app.js:16
  3. morgan('dev')app.js:17
  4. express.json()app.js:18
  5. express.urlencoded({ extended: true })app.js:19

Auth: ไม่มีทุก endpoint


1. GET / — Landing page

ItemDetail
Handlerinline res.sendFile(public/index.html)
Citationapp.js:36-38
ResponseHTML
Authไม่มี

หน้า landing ลิงก์ไป /health, /api, /api/health/detailed (public/index.html)


2. Static files

ItemDetail
Mountexpress.static(public/)
Citationapp.js:22
Files in repopublic/index.html เท่านั้น

3. GET /docs — Swagger UI

ItemDetail
HandlerswaggerUi.serve + setup(swaggerSpec, { explorer: true })
Citationapp.js:25
Spec sourcedocs/swagger.js (OpenAPI 3.0.0, title VTRC OCR API)
Server URL ใน spechttp://localhost:{config.port}docs/swagger.js:14-17

4. GET /docs.json — Raw OpenAPI

ItemDetail
Handlerinline send swaggerSpec
Citationapp.js:26-29
Content-Typeapplication/json

5. GET /health — Top-level health (นอก /api)

ItemDetail
Handlerinline ใน app.js
Citationapp.js:41-47

Response 200:

{
  "status": "OK",
  "message": "Server is running",
  "timestamp": "<ISO>"
}

ต่างจาก /api/health ทั้ง shape และ path — มีสอง health surface


6. GET /api — API root metadata

ItemDetail
Route fileroutes/index.js:35-44
Swagger tagGeneral (index.js:13-33)

Response 200:

{
  "message": "VTRC OCR API",
  "version": "1.0.0",
  "endpoints": {
    "health": "/api/health",
    "ocr": "/api/ocr"
  }
}

version จาก config.api.version (config.js:11)


7. GET /api/health — Basic API health

ItemDetail
Mountrouter.use('/health', healthRoutes)routes/index.js:10
RouteGET / บน health router — health.routes.js
ControllerhealthController.checkHealthhealth.controller.js:3-13
ServicegetHealthStatus()health.service.js:1-8

Response 200:

{
  "status": "healthy",
  "timestamp": "<ISO>",
  "uptime": <number>,
  "environment": "<NODE_ENV or development>"
}

Response 500:

{ "error": "Health check failed", "message": "<error.message>" }

(health.controller.js:8-11)

หมายเหตุ: response นี้ไม่มี wrapper { success, data } ต่างจาก OCR controllers


8. GET /api/health/detailed — Detailed health

ItemDetail
Routehealth.routes.js detailed path
ControllergetDetailedHealthhealth.controller.js:15-25
Servicehealth.service.js:10-24

Response 200:

{
  "status": "healthy",
  "timestamp": "<ISO>",
  "uptime": <number>,
  "environment": "<string>",
  "memory": { "used": <MB>, "total": <MB>, "unit": "MB" },
  "nodeVersion": "<process.version>",
  "platform": "<process.platform>"
}

Response 500:

{ "error": "Detailed health check failed", "message": "<error.message>" }

ไม่ตรวจ DB/OCR dependency (ยังไม่มีให้ตรวจ)


9. POST /api/ocr/process — Submit OCR job (MOCKED)

ItemDetail
Routeocr.routes.js:38
MiddlewarevalidateOCRRequest
ControllerprocessOCRocr.controller.js:3-18
ServiceprocessImageocr.service.js:6-41

Request body

FieldTypeRequiredValidationCitation
imagestringใช่notEmpty + isString (ข้อความบอกว่า base64 แต่ไม่ verify)validation.middleware.js:4-8, swagger OCRRequest
optionsobjectไม่optional isObjectvalidation.middleware.js:9-12

Response 200

{
  "success": true,
  "data": {
    "processingId": "ocr_<timestamp>_<random>",
    "status": "processing",
    "message": "OCR processing started"
  }
}

(ocr.controller.js:8-11, return shape ocr.service.js:36-40)

Response 400 (validation)

{ "success": false, "errors": [ /* express-validator */ ] }

Response 400 (service)

{ "success": false, "error": "Image is required" }

Response 500

{ "success": false, "error": "<message or 'OCR processing failed'>" }

หลัง 1 วินาที record ใน Map ถูกอัปเดตเป็น completed ด้วย text/confidence คงที่ — ดู 02-core-pipeline


10. GET /api/ocr/status/:id — Poll status

ItemDetail
Routeocr.routes.js:61
ControllergetStatusocr.controller.js:20-35
ServicegetProcessingStatusocr.service.js:43-51
Path paramid string

Response 200

{ "success": true, "data": <record> }

record ตาม lifecycle processing → completed (mock fields ตาม swagger OCRStatusResponse: id, status, text, confidence, createdAt, completedAt — docs/swagger.js:35-45)

Response 404

{ "success": false, "error": "Processing record not found" }

(ocr.service.js:46-48, controller ใช้ error.status || 404)


11. GET /api/ocr/history — Paginated history

ItemDetail
Routeocr.routes.js:84
ControllergetHistoryocr.controller.js:37-52
ServicegetProcessingHistoryocr.service.js:53-67

Query params

ParamDefaultValidationCitation
page1ไม่มี (string จาก query → parseInt ท้ายทาง)ocr.controller.js:39, swagger default 1
limit10ไม่มี同上

Response 200

{
  "success": true,
  "data": {
    "records": [ /* newest first */ ],
    "pagination": {
      "page": <int>,
      "limit": <int>,
      "total": <int>,
      "totalPages": <int>
    }
  }
}

Response 500

{ "success": false, "error": "<message or 'Failed to retrieve history'>" }

12. Catch-all 404

ItemDetail
Handlerapp.js:50-55
Response{ "error": "Not Found", "message": "Route <originalUrl> not found" }
Status404

13. Global error handler (inline)

ItemDetail
Handlerapp.js:58-64
Response{ "error": <message>, "stack"?: <dev only> }
Statuserr.status || 500

middleware/error.middleware.js มี errorHandler / asyncHandler แต่ไม่ถูก mount — dead code


สรุปตาราง endpoint

MethodPathMock/RealAuth
GET/HTML staticไม่มี
GET/docsSwagger UIไม่มี
GET/docs.jsonOpenAPI JSONไม่มี
GET/healthprocess aliveไม่มี
GET/apimetadataไม่มี
GET/api/healthprocess metricsไม่มี
GET/api/health/detailed+ memory/nodeไม่มี
POST/api/ocr/processMOCKไม่มี
GET/api/ocr/status/:idin-memory readไม่มี
GET/api/ocr/historyin-memory listไม่มี
*(unmatched)404 JSONไม่มี

Example curl (local default port 3000)

# metadata
curl -s http://localhost:3000/api

# submit mock job
curl -s -X POST http://localhost:3000/api/ocr/process \
  -H 'Content-Type: application/json' \
  -d '{"image":"dGVzdA==","options":{}}'

# poll (แทน {id} ด้วย processingId จากคำตอบ)
curl -s http://localhost:3000/api/ocr/status/{id}

# history
curl -s 'http://localhost:3000/api/ocr/history?page=1&limit=10'

ผล text หลัง completed จะเป็น 'Sample OCR result text' เสมอ — ไม่ขึ้นกับเนื้อหา image