Files
url-shortener/backend/src/routes/doc.routes.ts
T
2025-11-23 20:42:56 +01:00

35 lines
950 B
TypeScript

import { HttpMethod } from "@/lib/types"
const swaggerHtml = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>URL Shortener API</title>
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@5.9.0/swagger-ui.css" />
</head>
<body>
<div id="swagger-ui"></div>
<script src="https://unpkg.com/swagger-ui-dist@5.9.0/swagger-ui-bundle.js"></script>
<script>
window.onload = () => {
window.ui = SwaggerUIBundle({
url: '/api/openapi.json', // Apunta a tu ruta JSON anterior
dom_id: '#swagger-ui',
});
};
</script>
</body>
</html>
`
export const docRoutes = {
"/api/openapi.json": {
[HttpMethod.GET]: () => new Response(Bun.file("./openapi.json")),
},
"/api/docs": {
[HttpMethod.GET]: () =>
new Response(swaggerHtml, { headers: { "Content-Type": "text/html" } }),
},
}