create-daloy 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@ curl http://localhost:3000/books/1
|
|
|
18
18
|
|
|
19
19
|
## API documentation
|
|
20
20
|
|
|
21
|
-
-
|
|
21
|
+
- Swagger UI: <http://localhost:3000/docs>
|
|
22
22
|
- OpenAPI 3.1 JSON: <http://localhost:3000/openapi.json>
|
|
23
23
|
|
|
24
24
|
The spec is generated live from your routes, so it stays in sync with what is actually deployed.
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from "@daloyjs/core";
|
|
9
9
|
import { serve } from "@daloyjs/core/node";
|
|
10
10
|
import { generateOpenAPI } from "@daloyjs/core/openapi";
|
|
11
|
-
import { htmlResponse,
|
|
11
|
+
import { htmlResponse, swaggerUiHtml } from "@daloyjs/core/docs";
|
|
12
12
|
|
|
13
13
|
const app = new App({
|
|
14
14
|
bodyLimitBytes: 1024 * 1024,
|
|
@@ -64,7 +64,7 @@ const port = Number(process.env.PORT ?? 3000);
|
|
|
64
64
|
|
|
65
65
|
// --- API documentation -----------------------------------------------------
|
|
66
66
|
// `/openapi.json` returns the live OpenAPI 3.1 spec generated from the routes
|
|
67
|
-
// defined above. `/docs` serves a
|
|
67
|
+
// defined above. `/docs` serves a Swagger UI page that loads that spec.
|
|
68
68
|
|
|
69
69
|
app.route({
|
|
70
70
|
method: "GET",
|
|
@@ -88,7 +88,7 @@ app.route({
|
|
|
88
88
|
tags: ["Docs"],
|
|
89
89
|
responses: { 200: { description: "API reference UI" } },
|
|
90
90
|
handler: async () => {
|
|
91
|
-
const html =
|
|
91
|
+
const html = swaggerUiHtml({ specUrl: "/openapi.json", title: "My Daloy API" });
|
|
92
92
|
const res = htmlResponse(html);
|
|
93
93
|
return {
|
|
94
94
|
status: 200 as const,
|
|
@@ -100,6 +100,6 @@ app.route({
|
|
|
100
100
|
|
|
101
101
|
serve(app, { port });
|
|
102
102
|
console.log(`DaloyJS listening on http://localhost:${port}`);
|
|
103
|
-
console.log(`
|
|
103
|
+
console.log(` Swagger UI: http://localhost:${port}/docs`);
|
|
104
104
|
console.log(` OpenAPI JSON: http://localhost:${port}/openapi.json`);
|
|
105
105
|
console.log(` Health: http://localhost:${port}/healthz`);
|
|
@@ -18,7 +18,7 @@ curl http://localhost:3000/books/1
|
|
|
18
18
|
|
|
19
19
|
## API documentation
|
|
20
20
|
|
|
21
|
-
-
|
|
21
|
+
- Swagger UI: <http://localhost:3000/docs>
|
|
22
22
|
- OpenAPI 3.1 JSON: <http://localhost:3000/openapi.json>
|
|
23
23
|
|
|
24
24
|
After deploying, the same routes serve `/docs` and `/openapi.json` from your Vercel Edge URL.
|
|
@@ -2,7 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
import { App, NotFoundError, requestId, secureHeaders } from "@daloyjs/core";
|
|
3
3
|
import { toEdgeHandler } from "@daloyjs/core/vercel";
|
|
4
4
|
import { generateOpenAPI } from "@daloyjs/core/openapi";
|
|
5
|
-
import { htmlResponse,
|
|
5
|
+
import { htmlResponse, swaggerUiHtml } from "@daloyjs/core/docs";
|
|
6
6
|
|
|
7
7
|
export const config = { runtime: "edge" };
|
|
8
8
|
|
|
@@ -56,7 +56,7 @@ app.route({
|
|
|
56
56
|
|
|
57
57
|
// --- API documentation -----------------------------------------------------
|
|
58
58
|
// `/openapi.json` returns the OpenAPI 3.1 spec generated from the routes above.
|
|
59
|
-
// `/docs` serves a
|
|
59
|
+
// `/docs` serves a Swagger UI page that loads that spec.
|
|
60
60
|
|
|
61
61
|
app.route({
|
|
62
62
|
method: "GET",
|
|
@@ -79,7 +79,7 @@ app.route({
|
|
|
79
79
|
tags: ["Docs"],
|
|
80
80
|
responses: { 200: { description: "API reference UI" } },
|
|
81
81
|
handler: async () => {
|
|
82
|
-
const html =
|
|
82
|
+
const html = swaggerUiHtml({ specUrl: "/openapi.json", title: "My Daloy Edge API" });
|
|
83
83
|
const res = htmlResponse(html);
|
|
84
84
|
return {
|
|
85
85
|
status: 200 as const,
|