45 lines
1.6 KiB
TypeScript
45 lines
1.6 KiB
TypeScript
|
|
import { NextResponse } from "next/server";
|
||
|
|
|
||
|
|
import { openApiSpec } from "@/lib/openapi";
|
||
|
|
import { withBasePath } from "@/utils/base-path";
|
||
|
|
|
||
|
|
// GET /api/swagger — หน้า Swagger UI ของ API ทั้งหมด (กลุ่ม template + N10)
|
||
|
|
// (asset สำหรับ intranet: postinstall scripts/copy-swagger-ui.mjs คัดลอก
|
||
|
|
// swagger-ui-dist ไป public/note/swagger-ui/ — pattern เดียวกับ pdf.worker)
|
||
|
|
// spec inline จาก lib/openapi.ts ตรง ๆ ไม่มี endpoint spec แยก
|
||
|
|
export const runtime = "nodejs";
|
||
|
|
|
||
|
|
// กัน </script> ใน JSON ตัดสคริปต์ขาย (spec เป็นของเราเองทั้งหมด แค่กันกรณี
|
||
|
|
// ข้อความ example มี < ในอนาคต)
|
||
|
|
const SPEC_JSON = JSON.stringify(openApiSpec).replace(/</g, "\\u003c");
|
||
|
|
|
||
|
|
const HTML = `<!doctype html>
|
||
|
|
<html lang="th">
|
||
|
|
<head>
|
||
|
|
<meta charset="utf-8">
|
||
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
|
|
<title>Swagger UI — Judge's Note API</title>
|
||
|
|
<link rel="stylesheet" href="${withBasePath("/swagger-ui/swagger-ui.css")}">
|
||
|
|
</head>
|
||
|
|
<body>
|
||
|
|
<div id="swagger-ui"></div>
|
||
|
|
<script src="${withBasePath("/swagger-ui/swagger-ui-bundle.js")}"></script>
|
||
|
|
<script>
|
||
|
|
window.onload = function () {
|
||
|
|
window.ui = SwaggerUIBundle({
|
||
|
|
spec: ${SPEC_JSON},
|
||
|
|
dom_id: "#swagger-ui",
|
||
|
|
deepLinking: true,
|
||
|
|
persistAuthorization: true
|
||
|
|
});
|
||
|
|
};
|
||
|
|
</script>
|
||
|
|
</body>
|
||
|
|
</html>`;
|
||
|
|
|
||
|
|
export async function GET() {
|
||
|
|
return new NextResponse(HTML, {
|
||
|
|
headers: { "content-type": "text/html; charset=utf-8" },
|
||
|
|
});
|
||
|
|
}
|