@mergehez/dokie-node 0.1.2
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/LICENSE +21 -0
- package/README.md +186 -0
- package/assets/dokie.html +889 -0
- package/dist/index.cjs +266 -0
- package/dist/index.d.cts +113 -0
- package/dist/index.d.mts +113 -0
- package/dist/index.mjs +242 -0
- package/package.json +72 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Mazlum Özdogan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# Dokie for Node.js
|
|
2
|
+
|
|
3
|
+
A single Node.js package for serving the Dokie API documentation UI across generic servers, fetch-style runtimes, Express, Fastify, and Hono.
|
|
4
|
+
|
|
5
|
+
See the main repository at: [https://github.com/mergehez/dokie](https://github.com/mergehez/dokie)
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @mergehez/dokie-node
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Local development
|
|
14
|
+
|
|
15
|
+
Run package commands from `packages/node`:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
bun install
|
|
19
|
+
vp check --fix
|
|
20
|
+
bun run build
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
### Generic Node.js
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
import http from 'node:http';
|
|
29
|
+
import * as dokie from '@mergehez/dokie-node';
|
|
30
|
+
|
|
31
|
+
const server = http.createServer((req, res) => {
|
|
32
|
+
if (req.url !== '/dokie') {
|
|
33
|
+
res.statusCode = 404;
|
|
34
|
+
res.end('Not found');
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const html = dokie.renderDokieHtml(
|
|
39
|
+
{
|
|
40
|
+
openApiJsonUrl: '/openapi.json',
|
|
41
|
+
},
|
|
42
|
+
req
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
46
|
+
res.end(html);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
server.listen(3000);
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Custom server
|
|
53
|
+
|
|
54
|
+
Use `forCustomServer()` when your server is not Express, Fastify, or Hono, but can still provide an app-like `get(path, handler)` API plus request/response objects compatible with the exported `DokieRequestLike` and `DokieResponseLike` types.
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
import * as dokie from '@mergehez/dokie-node';
|
|
58
|
+
|
|
59
|
+
const customDokie = dokie.forCustomServer();
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Fetch-style runtimes
|
|
63
|
+
|
|
64
|
+
Use `forFetch()` for frameworks and runtimes built around web `Request` and `Response` objects, such as Next.js route handlers, Nuxt/Nitro server routes, Remix loaders/actions, Astro endpoints, and other fetch-based runtimes.
|
|
65
|
+
|
|
66
|
+
This is not a dedicated Next.js adapter. The example below works at the route-handler level because Next.js exposes the standard web `Request` and `Response` APIs there.
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
import * as dokie from '@mergehez/dokie-node';
|
|
70
|
+
|
|
71
|
+
export const GET = dokie.forFetch().createDokieHandler({
|
|
72
|
+
openApiJsonUrl: '/openapi.json',
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
#### Next.js route handler example
|
|
77
|
+
|
|
78
|
+
Example file: `app/dokie/route.ts`
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
import * as dokie from '@mergehez/dokie-node';
|
|
82
|
+
|
|
83
|
+
export const GET = dokie.forFetch().createDokieHandler({
|
|
84
|
+
openApiJsonUrl: '/openapi.json',
|
|
85
|
+
title: 'Dokie',
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
If you need deeper Next.js-specific behavior beyond a standard route handler, Dokie does not currently provide a dedicated Next.js integration layer.
|
|
90
|
+
|
|
91
|
+
### Express
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
import express from 'express';
|
|
95
|
+
import * as dokie from '@mergehez/dokie-node';
|
|
96
|
+
|
|
97
|
+
const app = express();
|
|
98
|
+
|
|
99
|
+
dokie.forExpress().registerDokieRoute(app, {
|
|
100
|
+
routePath: '/dokie',
|
|
101
|
+
title: 'Dokie',
|
|
102
|
+
openApiJsonUrl: '/openapi.json',
|
|
103
|
+
hostnames: ['https://api.example.com'],
|
|
104
|
+
variables: {
|
|
105
|
+
username: 'demo@example.com',
|
|
106
|
+
},
|
|
107
|
+
headers: {
|
|
108
|
+
'x-api-key': '',
|
|
109
|
+
},
|
|
110
|
+
bodies: {
|
|
111
|
+
'POST /api/login': JSON.stringify(
|
|
112
|
+
{
|
|
113
|
+
email: '{{username}}',
|
|
114
|
+
password: 'password',
|
|
115
|
+
},
|
|
116
|
+
null,
|
|
117
|
+
2
|
|
118
|
+
),
|
|
119
|
+
},
|
|
120
|
+
postscripts: {
|
|
121
|
+
'POST /api/login': "envs.headers['x-api-key'] = response.data.value.token;",
|
|
122
|
+
},
|
|
123
|
+
favorites: ['POST /api/login'],
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
app.listen(3000);
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Fastify
|
|
130
|
+
|
|
131
|
+
```js
|
|
132
|
+
import Fastify from 'fastify';
|
|
133
|
+
import * as dokie from '@mergehez/dokie-node';
|
|
134
|
+
|
|
135
|
+
const app = Fastify();
|
|
136
|
+
|
|
137
|
+
dokie.forFastify().registerDokieRoute(app, {
|
|
138
|
+
openApiJsonUrl: '/openapi.json',
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
await app.listen({ port: 3000 });
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Hono
|
|
145
|
+
|
|
146
|
+
```js
|
|
147
|
+
import { Hono } from 'hono';
|
|
148
|
+
import * as dokie from '@mergehez/dokie-node';
|
|
149
|
+
|
|
150
|
+
const app = new Hono();
|
|
151
|
+
|
|
152
|
+
dokie.forHono().registerDokieRoute(app, {
|
|
153
|
+
openApiJsonUrl: '/openapi.json',
|
|
154
|
+
});
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Options
|
|
158
|
+
|
|
159
|
+
- `routePath`: route registered by `registerDokieRoute`. Defaults to `/dokie`.
|
|
160
|
+
- `title`: optional page title.
|
|
161
|
+
- `currentHostname`: explicit base URL. By default it is inferred from the incoming request.
|
|
162
|
+
- `openApiJsonUrl`: OpenAPI JSON URL. Defaults to `/openapi.json`.
|
|
163
|
+
- `hostnames`: alternate hostnames shown in the UI. Defaults to `[currentHostname]` when available.
|
|
164
|
+
- `variables`: predefined environment variables.
|
|
165
|
+
- `headers`: predefined global headers.
|
|
166
|
+
- `bodies`: predefined request bodies by endpoint id.
|
|
167
|
+
- `postscripts`: predefined post-request scripts by endpoint id.
|
|
168
|
+
- `favorites`: predefined favorite endpoint ids.
|
|
169
|
+
- `assetPath`: override the path to `dokie.html` if needed.
|
|
170
|
+
|
|
171
|
+
## Exports
|
|
172
|
+
|
|
173
|
+
- `renderDokieHtml(options, req)`
|
|
174
|
+
- `createDokieHandler(options)`
|
|
175
|
+
- `createDokieMiddleware(options)`
|
|
176
|
+
- `registerDokieRoute(app, options)`
|
|
177
|
+
- `getDokieAssetPath()`
|
|
178
|
+
- `forCustomServer()`
|
|
179
|
+
- `forExpress()`
|
|
180
|
+
- `forFastify()`
|
|
181
|
+
- `forFetch()`
|
|
182
|
+
- `forHono()`
|
|
183
|
+
|
|
184
|
+
## License
|
|
185
|
+
|
|
186
|
+
This package is open-sourced software licensed under the [MIT license](LICENSE).
|