@jaredwray/mockhttp 0.0.1 → 0.2.0
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/README.md +5 -3
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1078 -32
- package/package.json +25 -13
- package/dist/fastify-config.js +0 -12
- package/dist/routes/delete-route.js +0 -27
- package/dist/routes/get-route.js +0 -34
- package/dist/routes/http-methods/delete.js +0 -28
- package/dist/routes/http-methods/get.js +0 -35
- package/dist/routes/http-methods/index.js +0 -5
- package/dist/routes/http-methods/patch.js +0 -28
- package/dist/routes/http-methods/post.js +0 -28
- package/dist/routes/http-methods/put.js +0 -28
- package/dist/routes/index-route.js +0 -67
- package/dist/routes/ip-route.js +0 -25
- package/dist/routes/post-route.js +0 -27
- package/dist/routes/put-route.js +0 -27
- package/dist/routes/request-inspection/headers.js +0 -26
- package/dist/routes/request-inspection/index.js +0 -3
- package/dist/routes/request-inspection/ip.js +0 -26
- package/dist/routes/request-inspection/user-agent.js +0 -25
- package/dist/routes/status-codes/get.js +0 -29
- package/dist/routes/status-codes/index.js +0 -102
- package/dist/routes/status-route.js +0 -28
- package/dist/swagger.js +0 -34
package/dist/index.js
CHANGED
|
@@ -1,48 +1,1094 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
//
|
|
13
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/index.ts
|
|
5
|
+
import process from "node:process";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import Fastify from "fastify";
|
|
8
|
+
import fastifyStatic from "@fastify/static";
|
|
9
|
+
import { fastifySwagger } from "@fastify/swagger";
|
|
10
|
+
import fastifyHelmet from "@fastify/helmet";
|
|
11
|
+
|
|
12
|
+
// src/routes/index-route.ts
|
|
13
|
+
var indexRoute = /* @__PURE__ */ __name((fastify2) => {
|
|
14
|
+
fastify2.get("/", {
|
|
15
|
+
schema: {
|
|
16
|
+
hide: true
|
|
17
|
+
}
|
|
18
|
+
}, async (_request, reply) => {
|
|
19
|
+
const redocHtml = `
|
|
20
|
+
<!doctype html>
|
|
21
|
+
<html>
|
|
22
|
+
<head>
|
|
23
|
+
<title>{ mockhttp }</title>
|
|
24
|
+
<meta charset="utf-8" />
|
|
25
|
+
<meta
|
|
26
|
+
name="viewport"
|
|
27
|
+
content="width=device-width, initial-scale=1" />
|
|
28
|
+
<style>
|
|
29
|
+
:root {
|
|
30
|
+
--scalar-custom-header-height: 70px;
|
|
31
|
+
}
|
|
32
|
+
.custom-header {
|
|
33
|
+
height: var(--scalar-custom-header-height);
|
|
34
|
+
background-color: var(--scalar-background-1);
|
|
35
|
+
box-shadow: inset 0 -1px 0 var(--scalar-border-color);
|
|
36
|
+
color: var(--scalar-color-1);
|
|
37
|
+
font-size: var(--scalar-font-size-2);
|
|
38
|
+
padding: 0 18px;
|
|
39
|
+
position: sticky;
|
|
40
|
+
justify-content: space-between;
|
|
41
|
+
top: 0;
|
|
42
|
+
z-index: 100;
|
|
43
|
+
}
|
|
44
|
+
.custom-header,
|
|
45
|
+
.custom-header nav {
|
|
46
|
+
display: flex;
|
|
47
|
+
align-items: center;
|
|
48
|
+
gap: 18px;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.custom-header img {
|
|
52
|
+
height: var(--scalar-custom-header-height);
|
|
53
|
+
object-fit: contain;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.custom-header a:hover {
|
|
57
|
+
color: var(--scalar-color-2);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.github-corner {
|
|
61
|
+
fill: var(--scalar-border-color) !important;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
</style>
|
|
65
|
+
</head>
|
|
66
|
+
<body>
|
|
67
|
+
<header class="custom-header scalar-app">
|
|
68
|
+
<a href="/"><img src="/logo.svg" alt="{ mockhttp }" /></a>
|
|
69
|
+
<a href="https://github.com/jaredwray/mockhttp" class="github-corner" aria-label="View source on GitHub">
|
|
70
|
+
<svg width="70" height="70" viewBox="0 0 250 250" style="color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
|
|
71
|
+
</header>
|
|
72
|
+
|
|
73
|
+
<script
|
|
74
|
+
id="api-reference"
|
|
75
|
+
data-url="/docs/json"></script>
|
|
76
|
+
|
|
77
|
+
<script src="/scalar/browser/standalone.js"></script>
|
|
78
|
+
</body>
|
|
79
|
+
</html>
|
|
80
|
+
`;
|
|
81
|
+
await reply.type("text/html").send(redocHtml);
|
|
82
|
+
});
|
|
83
|
+
}, "indexRoute");
|
|
84
|
+
|
|
85
|
+
// src/fastify-config.ts
|
|
86
|
+
var fastifyConfig = {
|
|
87
|
+
logger: {
|
|
88
|
+
transport: {
|
|
89
|
+
target: "pino-pretty",
|
|
90
|
+
options: {
|
|
91
|
+
colorize: true,
|
|
92
|
+
translateTime: true,
|
|
93
|
+
ignore: "pid,hostname"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// src/swagger.ts
|
|
100
|
+
import { fastifySwaggerUi } from "@fastify/swagger-ui";
|
|
101
|
+
|
|
102
|
+
// package.json
|
|
103
|
+
var package_default = {
|
|
104
|
+
name: "@jaredwray/mockhttp",
|
|
105
|
+
version: "0.2.0",
|
|
106
|
+
description: "Mock Http - Easy way to mock http with httpbin replacement",
|
|
107
|
+
type: "module",
|
|
108
|
+
main: "dist/index.js",
|
|
109
|
+
directories: {
|
|
110
|
+
test: "test"
|
|
111
|
+
},
|
|
112
|
+
scripts: {
|
|
113
|
+
test: "xo --fix && vitest run --coverage",
|
|
114
|
+
dev: "xo --fix && npx tsx src/index.ts --watch",
|
|
115
|
+
build: "rimraf ./dist && tsup src/index.ts --format esm --dts --clean",
|
|
116
|
+
"docker:build": "docker build -t jaredwray/mockhttp .",
|
|
117
|
+
"docker:run": "docker run -p 3000:3000 jaredwray/mockhttp",
|
|
118
|
+
"docker:push": "docker push jaredwray/mockhttp",
|
|
119
|
+
"docker:stop": 'docker stop $(docker ps -a -q --filter ancestor=jaredwray/mockhttp --format="{{.ID}}")',
|
|
120
|
+
prepare: "npm run build",
|
|
121
|
+
start: "node dist/index.js"
|
|
122
|
+
},
|
|
123
|
+
repository: {
|
|
124
|
+
type: "git",
|
|
125
|
+
url: "git+https://github.com/jaredwray/mockhttp.git"
|
|
126
|
+
},
|
|
127
|
+
keywords: [
|
|
128
|
+
"mock",
|
|
129
|
+
"http",
|
|
130
|
+
"httpbin",
|
|
131
|
+
"test"
|
|
132
|
+
],
|
|
133
|
+
author: "Jared Wray <me@jaredwray.com>",
|
|
134
|
+
license: "MIT",
|
|
135
|
+
bugs: {
|
|
136
|
+
url: "https://github.com/jaredwray/mockhttp/issues"
|
|
137
|
+
},
|
|
138
|
+
homepage: "https://github.com/jaredwray/mockhttp#readme",
|
|
139
|
+
devDependencies: {
|
|
140
|
+
"@swc/core": "^1.10.1",
|
|
141
|
+
"@types/html-escaper": "^3.0.2",
|
|
142
|
+
"@vitest/coverage-v8": "^2.1.8",
|
|
143
|
+
rimraf: "^6.0.1",
|
|
144
|
+
tsup: "^8.3.5",
|
|
145
|
+
tsx: "^4.19.2",
|
|
146
|
+
typescript: "^5.7.2",
|
|
147
|
+
vitest: "^2.1.8",
|
|
148
|
+
xo: "^0.60.0"
|
|
149
|
+
},
|
|
150
|
+
dependencies: {
|
|
151
|
+
"@fastify/helmet": "^13.0.0",
|
|
152
|
+
"@fastify/static": "^8.0.3",
|
|
153
|
+
"@fastify/swagger": "^9.4.0",
|
|
154
|
+
"@fastify/swagger-ui": "^5.2.0",
|
|
155
|
+
"@scalar/api-reference": "^1.25.80",
|
|
156
|
+
fastify: "^5.1.0",
|
|
157
|
+
"html-escaper": "^3.0.3",
|
|
158
|
+
pino: "^9.5.0",
|
|
159
|
+
"pino-pretty": "^13.0.0"
|
|
160
|
+
},
|
|
161
|
+
files: [
|
|
162
|
+
"dist",
|
|
163
|
+
"public",
|
|
164
|
+
"LICENCE"
|
|
165
|
+
]
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// src/swagger.ts
|
|
169
|
+
var fastifySwaggerConfig = {
|
|
170
|
+
openapi: {
|
|
171
|
+
info: {
|
|
172
|
+
title: "Mock HTTP API",
|
|
173
|
+
description: "A replacement for httpbin built using Fastify and Typescript",
|
|
174
|
+
version: package_default.version
|
|
175
|
+
},
|
|
176
|
+
consumes: [
|
|
177
|
+
"application/json"
|
|
178
|
+
],
|
|
179
|
+
produces: [
|
|
180
|
+
"application/json"
|
|
181
|
+
]
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
var registerSwaggerUi = /* @__PURE__ */ __name(async (fastify2) => {
|
|
185
|
+
await fastify2.register(fastifySwaggerUi, {
|
|
186
|
+
routePrefix: "/docs",
|
|
187
|
+
uiConfig: {
|
|
188
|
+
docExpansion: "none",
|
|
189
|
+
deepLinking: false
|
|
190
|
+
},
|
|
191
|
+
uiHooks: {
|
|
192
|
+
/* c8 ignore next 6 */
|
|
193
|
+
onRequest(_request, _reply, next) {
|
|
194
|
+
next();
|
|
195
|
+
},
|
|
196
|
+
preHandler(_request, _reply, next) {
|
|
197
|
+
next();
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
201
|
+
staticCSP: true,
|
|
202
|
+
transformSpecification: /* @__PURE__ */ __name((swaggerObject, _request, _reply) => swaggerObject, "transformSpecification"),
|
|
203
|
+
transformSpecificationClone: true
|
|
204
|
+
});
|
|
205
|
+
}, "registerSwaggerUi");
|
|
206
|
+
|
|
207
|
+
// src/routes/request-inspection/ip.ts
|
|
208
|
+
var ipSchema = {
|
|
209
|
+
description: "Returns the IP address of the client",
|
|
210
|
+
tags: [
|
|
211
|
+
"Request Inspection"
|
|
212
|
+
],
|
|
213
|
+
response: {
|
|
214
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
215
|
+
200: {
|
|
216
|
+
type: "object",
|
|
217
|
+
properties: {
|
|
218
|
+
ip: {
|
|
219
|
+
type: "string",
|
|
220
|
+
description: "The IP address of the client"
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
required: [
|
|
224
|
+
"ip"
|
|
225
|
+
]
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
var ipRoute = /* @__PURE__ */ __name((fastify2) => {
|
|
230
|
+
fastify2.get("/ip", {
|
|
231
|
+
schema: ipSchema
|
|
232
|
+
}, async (request) => {
|
|
233
|
+
const cloudflareIp = request.headers["cf-connecting-ip"];
|
|
234
|
+
const forwardedIp = request.headers["x-forwarded-for"];
|
|
235
|
+
const remoteIp = request.ip;
|
|
236
|
+
const ip = cloudflareIp ?? (typeof forwardedIp === "string" ? forwardedIp.split(",")[0].trim() : remoteIp);
|
|
237
|
+
return {
|
|
238
|
+
ip
|
|
239
|
+
};
|
|
240
|
+
});
|
|
241
|
+
}, "ipRoute");
|
|
242
|
+
|
|
243
|
+
// src/routes/request-inspection/headers.ts
|
|
244
|
+
var headersSchema = {
|
|
245
|
+
description: "Returns all headers of the client request",
|
|
246
|
+
tags: [
|
|
247
|
+
"Request Inspection"
|
|
248
|
+
],
|
|
249
|
+
response: {
|
|
250
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
251
|
+
200: {
|
|
252
|
+
type: "object",
|
|
253
|
+
properties: {
|
|
254
|
+
headers: {
|
|
255
|
+
type: "object",
|
|
256
|
+
additionalProperties: {
|
|
257
|
+
type: "string"
|
|
258
|
+
},
|
|
259
|
+
description: "All headers of the client request"
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
required: [
|
|
263
|
+
"headers"
|
|
264
|
+
]
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
var headersRoute = /* @__PURE__ */ __name((fastify2) => {
|
|
269
|
+
fastify2.get("/headers", {
|
|
270
|
+
schema: headersSchema
|
|
271
|
+
}, async (request) => {
|
|
272
|
+
const headers = request.headers;
|
|
273
|
+
return {
|
|
274
|
+
headers
|
|
275
|
+
};
|
|
276
|
+
});
|
|
277
|
+
}, "headersRoute");
|
|
278
|
+
|
|
279
|
+
// src/routes/request-inspection/user-agent.ts
|
|
280
|
+
var userAgentSchema = {
|
|
281
|
+
description: "Returns the User-Agent header of the client request",
|
|
282
|
+
tags: [
|
|
283
|
+
"Request Inspection"
|
|
284
|
+
],
|
|
285
|
+
response: {
|
|
286
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
287
|
+
200: {
|
|
288
|
+
type: "object",
|
|
289
|
+
properties: {
|
|
290
|
+
userAgent: {
|
|
291
|
+
type: "string",
|
|
292
|
+
description: "The User-Agent header of the client request"
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
required: [
|
|
296
|
+
"userAgent"
|
|
297
|
+
]
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
var userAgentRoute = /* @__PURE__ */ __name((fastify2) => {
|
|
302
|
+
fastify2.get("/user-agent", {
|
|
303
|
+
schema: userAgentSchema
|
|
304
|
+
}, async (request) => {
|
|
305
|
+
const userAgent = request.headers["user-agent"];
|
|
306
|
+
return {
|
|
307
|
+
userAgent
|
|
308
|
+
};
|
|
309
|
+
});
|
|
310
|
+
}, "userAgentRoute");
|
|
311
|
+
|
|
312
|
+
// src/routes/http-methods/get.ts
|
|
313
|
+
var getSchema = {
|
|
314
|
+
description: "Returns request information for GET requests",
|
|
315
|
+
tags: [
|
|
316
|
+
"HTTP Methods"
|
|
317
|
+
],
|
|
318
|
+
querystring: {
|
|
319
|
+
type: "object",
|
|
320
|
+
additionalProperties: true,
|
|
321
|
+
properties: {},
|
|
322
|
+
description: "Query parameters sent in the request"
|
|
323
|
+
},
|
|
324
|
+
headers: {
|
|
325
|
+
type: "object",
|
|
326
|
+
additionalProperties: true,
|
|
327
|
+
properties: {},
|
|
328
|
+
description: "Headers sent in the request"
|
|
329
|
+
},
|
|
330
|
+
response: {
|
|
331
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
332
|
+
200: {
|
|
333
|
+
type: "object",
|
|
334
|
+
properties: {
|
|
335
|
+
method: {
|
|
336
|
+
type: "string"
|
|
337
|
+
},
|
|
338
|
+
headers: {
|
|
339
|
+
type: "object",
|
|
340
|
+
additionalProperties: {
|
|
341
|
+
type: "string"
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
queryParams: {
|
|
345
|
+
type: "object",
|
|
346
|
+
additionalProperties: {
|
|
347
|
+
type: "string"
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
},
|
|
351
|
+
required: [
|
|
352
|
+
"method",
|
|
353
|
+
"headers",
|
|
354
|
+
"queryParams"
|
|
355
|
+
]
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
var getRoute = /* @__PURE__ */ __name((fastify2) => {
|
|
360
|
+
fastify2.get("/get", {
|
|
361
|
+
schema: getSchema
|
|
362
|
+
}, async (request, _reply) => ({
|
|
363
|
+
method: "GET",
|
|
364
|
+
headers: request.headers,
|
|
365
|
+
queryParams: request.query
|
|
366
|
+
}));
|
|
367
|
+
}, "getRoute");
|
|
368
|
+
|
|
369
|
+
// src/routes/http-methods/post.ts
|
|
370
|
+
var postSchema = {
|
|
371
|
+
description: "Handles a POST request and returns request information",
|
|
372
|
+
tags: [
|
|
373
|
+
"HTTP Methods"
|
|
374
|
+
],
|
|
375
|
+
body: {
|
|
376
|
+
type: "object",
|
|
377
|
+
additionalProperties: true,
|
|
378
|
+
description: "The body of the POST request"
|
|
379
|
+
},
|
|
380
|
+
response: {
|
|
381
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
382
|
+
200: {
|
|
383
|
+
type: "object",
|
|
384
|
+
properties: {
|
|
385
|
+
method: {
|
|
386
|
+
type: "string"
|
|
387
|
+
},
|
|
388
|
+
headers: {
|
|
389
|
+
type: "object",
|
|
390
|
+
additionalProperties: {
|
|
391
|
+
type: "string"
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
body: {
|
|
395
|
+
type: "object",
|
|
396
|
+
additionalProperties: true
|
|
397
|
+
}
|
|
398
|
+
},
|
|
399
|
+
required: [
|
|
400
|
+
"method",
|
|
401
|
+
"headers",
|
|
402
|
+
"body"
|
|
403
|
+
]
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
var postRoute = /* @__PURE__ */ __name((fastify2) => {
|
|
408
|
+
fastify2.post("/post", {
|
|
409
|
+
schema: postSchema
|
|
410
|
+
}, async (request) => ({
|
|
411
|
+
method: "POST",
|
|
412
|
+
headers: request.headers,
|
|
413
|
+
body: request.body
|
|
414
|
+
}));
|
|
415
|
+
}, "postRoute");
|
|
416
|
+
|
|
417
|
+
// src/routes/http-methods/delete.ts
|
|
418
|
+
var deleteSchema = {
|
|
419
|
+
description: "Handles a DELETE request and returns request information",
|
|
420
|
+
tags: [
|
|
421
|
+
"HTTP Methods"
|
|
422
|
+
],
|
|
423
|
+
body: {
|
|
424
|
+
type: "object",
|
|
425
|
+
additionalProperties: true,
|
|
426
|
+
description: "The body of the DELETE request"
|
|
427
|
+
},
|
|
428
|
+
response: {
|
|
429
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
430
|
+
200: {
|
|
431
|
+
type: "object",
|
|
432
|
+
properties: {
|
|
433
|
+
method: {
|
|
434
|
+
type: "string"
|
|
435
|
+
},
|
|
436
|
+
headers: {
|
|
437
|
+
type: "object",
|
|
438
|
+
additionalProperties: {
|
|
439
|
+
type: "string"
|
|
440
|
+
}
|
|
441
|
+
},
|
|
442
|
+
body: {
|
|
443
|
+
type: "object",
|
|
444
|
+
additionalProperties: true
|
|
445
|
+
}
|
|
446
|
+
},
|
|
447
|
+
required: [
|
|
448
|
+
"method",
|
|
449
|
+
"headers",
|
|
450
|
+
"body"
|
|
451
|
+
]
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
var deleteRoute = /* @__PURE__ */ __name((fastify2) => {
|
|
456
|
+
fastify2.delete("/delete", {
|
|
457
|
+
schema: deleteSchema
|
|
458
|
+
}, async (request) => ({
|
|
459
|
+
method: "DELETE",
|
|
460
|
+
headers: request.headers,
|
|
461
|
+
body: request.body
|
|
462
|
+
}));
|
|
463
|
+
}, "deleteRoute");
|
|
464
|
+
|
|
465
|
+
// src/routes/http-methods/put.ts
|
|
466
|
+
var putSchema = {
|
|
467
|
+
description: "Handles a PUT request and returns request information",
|
|
468
|
+
tags: [
|
|
469
|
+
"HTTP Methods"
|
|
470
|
+
],
|
|
471
|
+
body: {
|
|
472
|
+
type: "object",
|
|
473
|
+
additionalProperties: true,
|
|
474
|
+
description: "The body of the PUT request"
|
|
475
|
+
},
|
|
476
|
+
response: {
|
|
477
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
478
|
+
200: {
|
|
479
|
+
type: "object",
|
|
480
|
+
properties: {
|
|
481
|
+
method: {
|
|
482
|
+
type: "string"
|
|
483
|
+
},
|
|
484
|
+
headers: {
|
|
485
|
+
type: "object",
|
|
486
|
+
additionalProperties: {
|
|
487
|
+
type: "string"
|
|
488
|
+
}
|
|
489
|
+
},
|
|
490
|
+
body: {
|
|
491
|
+
type: "object",
|
|
492
|
+
additionalProperties: true
|
|
493
|
+
}
|
|
494
|
+
},
|
|
495
|
+
required: [
|
|
496
|
+
"method",
|
|
497
|
+
"headers",
|
|
498
|
+
"body"
|
|
499
|
+
]
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
var putRoute = /* @__PURE__ */ __name((fastify2) => {
|
|
504
|
+
fastify2.put("/put", {
|
|
505
|
+
schema: putSchema
|
|
506
|
+
}, async (request) => ({
|
|
507
|
+
method: "PUT",
|
|
508
|
+
headers: request.headers,
|
|
509
|
+
body: request.body
|
|
510
|
+
}));
|
|
511
|
+
}, "putRoute");
|
|
512
|
+
|
|
513
|
+
// src/routes/http-methods/patch.ts
|
|
514
|
+
var patchSchema = {
|
|
515
|
+
description: "Handles a PATCH request and returns request information",
|
|
516
|
+
tags: [
|
|
517
|
+
"HTTP Methods"
|
|
518
|
+
],
|
|
519
|
+
body: {
|
|
520
|
+
type: "object",
|
|
521
|
+
additionalProperties: true,
|
|
522
|
+
description: "The body of the PATCH request"
|
|
523
|
+
},
|
|
524
|
+
response: {
|
|
525
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
526
|
+
200: {
|
|
527
|
+
type: "object",
|
|
528
|
+
properties: {
|
|
529
|
+
method: {
|
|
530
|
+
type: "string"
|
|
531
|
+
},
|
|
532
|
+
headers: {
|
|
533
|
+
type: "object",
|
|
534
|
+
additionalProperties: {
|
|
535
|
+
type: "string"
|
|
536
|
+
}
|
|
537
|
+
},
|
|
538
|
+
body: {
|
|
539
|
+
type: "object",
|
|
540
|
+
additionalProperties: true
|
|
541
|
+
}
|
|
542
|
+
},
|
|
543
|
+
required: [
|
|
544
|
+
"method",
|
|
545
|
+
"headers",
|
|
546
|
+
"body"
|
|
547
|
+
]
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
var patchRoute = /* @__PURE__ */ __name((fastify2) => {
|
|
552
|
+
fastify2.patch("/patch", {
|
|
553
|
+
schema: patchSchema
|
|
554
|
+
}, async (request) => ({
|
|
555
|
+
method: "PATCH",
|
|
556
|
+
headers: request.headers,
|
|
557
|
+
body: request.body
|
|
558
|
+
}));
|
|
559
|
+
}, "patchRoute");
|
|
560
|
+
|
|
561
|
+
// src/routes/status-codes/index.ts
|
|
562
|
+
import { randomInt } from "node:crypto";
|
|
563
|
+
var statusCodes = [
|
|
564
|
+
{
|
|
565
|
+
code: 100,
|
|
566
|
+
message: "Continue"
|
|
567
|
+
},
|
|
568
|
+
{
|
|
569
|
+
code: 101,
|
|
570
|
+
message: "Switching Protocols"
|
|
571
|
+
},
|
|
572
|
+
{
|
|
573
|
+
code: 102,
|
|
574
|
+
message: "Processing"
|
|
575
|
+
},
|
|
576
|
+
{
|
|
577
|
+
code: 103,
|
|
578
|
+
message: "Early Hints"
|
|
579
|
+
},
|
|
580
|
+
{
|
|
581
|
+
code: 200,
|
|
582
|
+
message: "OK"
|
|
583
|
+
},
|
|
584
|
+
{
|
|
585
|
+
code: 201,
|
|
586
|
+
message: "Created"
|
|
587
|
+
},
|
|
588
|
+
{
|
|
589
|
+
code: 202,
|
|
590
|
+
message: "Accepted"
|
|
591
|
+
},
|
|
592
|
+
{
|
|
593
|
+
code: 203,
|
|
594
|
+
message: "Non-Authoritative Information"
|
|
595
|
+
},
|
|
596
|
+
{
|
|
597
|
+
code: 204,
|
|
598
|
+
message: "No Content"
|
|
599
|
+
},
|
|
600
|
+
{
|
|
601
|
+
code: 205,
|
|
602
|
+
message: "Reset Content"
|
|
603
|
+
},
|
|
604
|
+
{
|
|
605
|
+
code: 206,
|
|
606
|
+
message: "Partial Content"
|
|
607
|
+
},
|
|
608
|
+
{
|
|
609
|
+
code: 207,
|
|
610
|
+
message: "Multi-Status"
|
|
611
|
+
},
|
|
612
|
+
{
|
|
613
|
+
code: 208,
|
|
614
|
+
message: "Already Reported"
|
|
615
|
+
},
|
|
616
|
+
{
|
|
617
|
+
code: 226,
|
|
618
|
+
message: "IM Used"
|
|
619
|
+
},
|
|
620
|
+
{
|
|
621
|
+
code: 300,
|
|
622
|
+
message: "Multiple Choices"
|
|
623
|
+
},
|
|
624
|
+
{
|
|
625
|
+
code: 301,
|
|
626
|
+
message: "Moved Permanently"
|
|
627
|
+
},
|
|
628
|
+
{
|
|
629
|
+
code: 302,
|
|
630
|
+
message: "Found"
|
|
631
|
+
},
|
|
632
|
+
{
|
|
633
|
+
code: 303,
|
|
634
|
+
message: "See Other"
|
|
635
|
+
},
|
|
636
|
+
{
|
|
637
|
+
code: 304,
|
|
638
|
+
message: "Not Modified"
|
|
639
|
+
},
|
|
640
|
+
{
|
|
641
|
+
code: 305,
|
|
642
|
+
message: "Use Proxy"
|
|
643
|
+
},
|
|
644
|
+
{
|
|
645
|
+
code: 306,
|
|
646
|
+
message: "Switch Proxy"
|
|
647
|
+
},
|
|
648
|
+
{
|
|
649
|
+
code: 307,
|
|
650
|
+
message: "Temporary Redirect"
|
|
651
|
+
},
|
|
652
|
+
{
|
|
653
|
+
code: 308,
|
|
654
|
+
message: "Permanent Redirect"
|
|
655
|
+
},
|
|
656
|
+
{
|
|
657
|
+
code: 400,
|
|
658
|
+
message: "Bad Request"
|
|
659
|
+
},
|
|
660
|
+
{
|
|
661
|
+
code: 401,
|
|
662
|
+
message: "Unauthorized"
|
|
663
|
+
},
|
|
664
|
+
{
|
|
665
|
+
code: 402,
|
|
666
|
+
message: "Payment Required"
|
|
667
|
+
},
|
|
668
|
+
{
|
|
669
|
+
code: 403,
|
|
670
|
+
message: "Forbidden"
|
|
671
|
+
},
|
|
672
|
+
{
|
|
673
|
+
code: 404,
|
|
674
|
+
message: "Not Found"
|
|
675
|
+
},
|
|
676
|
+
{
|
|
677
|
+
code: 405,
|
|
678
|
+
message: "Method Not Allowed"
|
|
679
|
+
},
|
|
680
|
+
{
|
|
681
|
+
code: 406,
|
|
682
|
+
message: "Not Acceptable"
|
|
683
|
+
},
|
|
684
|
+
{
|
|
685
|
+
code: 407,
|
|
686
|
+
message: "Proxy Authentication Required"
|
|
687
|
+
},
|
|
688
|
+
{
|
|
689
|
+
code: 408,
|
|
690
|
+
message: "Request Timeout"
|
|
691
|
+
},
|
|
692
|
+
{
|
|
693
|
+
code: 409,
|
|
694
|
+
message: "Conflict"
|
|
695
|
+
},
|
|
696
|
+
{
|
|
697
|
+
code: 410,
|
|
698
|
+
message: "Gone"
|
|
699
|
+
},
|
|
700
|
+
{
|
|
701
|
+
code: 411,
|
|
702
|
+
message: "Length Required"
|
|
703
|
+
},
|
|
704
|
+
{
|
|
705
|
+
code: 412,
|
|
706
|
+
message: "Precondition Failed"
|
|
707
|
+
},
|
|
708
|
+
{
|
|
709
|
+
code: 413,
|
|
710
|
+
message: "Payload Too Large"
|
|
711
|
+
},
|
|
712
|
+
{
|
|
713
|
+
code: 414,
|
|
714
|
+
message: "URI Too Long"
|
|
715
|
+
},
|
|
716
|
+
{
|
|
717
|
+
code: 415,
|
|
718
|
+
message: "Unsupported Media Type"
|
|
719
|
+
},
|
|
720
|
+
{
|
|
721
|
+
code: 416,
|
|
722
|
+
message: "Range Not Satisfiable"
|
|
723
|
+
},
|
|
724
|
+
{
|
|
725
|
+
code: 417,
|
|
726
|
+
message: "Expectation Failed"
|
|
727
|
+
},
|
|
728
|
+
{
|
|
729
|
+
code: 418,
|
|
730
|
+
message: "I'm a teapot"
|
|
731
|
+
},
|
|
732
|
+
{
|
|
733
|
+
code: 421,
|
|
734
|
+
message: "Misdirected Request"
|
|
735
|
+
},
|
|
736
|
+
{
|
|
737
|
+
code: 422,
|
|
738
|
+
message: "Unprocessable Entity"
|
|
739
|
+
},
|
|
740
|
+
{
|
|
741
|
+
code: 423,
|
|
742
|
+
message: "Locked"
|
|
743
|
+
},
|
|
744
|
+
{
|
|
745
|
+
code: 424,
|
|
746
|
+
message: "Failed Dependency"
|
|
747
|
+
},
|
|
748
|
+
{
|
|
749
|
+
code: 425,
|
|
750
|
+
message: "Too Early"
|
|
751
|
+
},
|
|
752
|
+
{
|
|
753
|
+
code: 426,
|
|
754
|
+
message: "Upgrade Required"
|
|
755
|
+
},
|
|
756
|
+
{
|
|
757
|
+
code: 428,
|
|
758
|
+
message: "Precondition Required"
|
|
759
|
+
},
|
|
760
|
+
{
|
|
761
|
+
code: 429,
|
|
762
|
+
message: "Too Many Requests"
|
|
763
|
+
},
|
|
764
|
+
{
|
|
765
|
+
code: 431,
|
|
766
|
+
message: "Request Header Fields Too Large"
|
|
767
|
+
},
|
|
768
|
+
{
|
|
769
|
+
code: 451,
|
|
770
|
+
message: "Unavailable For Legal Reasons"
|
|
771
|
+
},
|
|
772
|
+
{
|
|
773
|
+
code: 500,
|
|
774
|
+
message: "Internal Server Error"
|
|
775
|
+
},
|
|
776
|
+
{
|
|
777
|
+
code: 501,
|
|
778
|
+
message: "Not Implemented"
|
|
779
|
+
},
|
|
780
|
+
{
|
|
781
|
+
code: 502,
|
|
782
|
+
message: "Bad Gateway"
|
|
783
|
+
},
|
|
784
|
+
{
|
|
785
|
+
code: 503,
|
|
786
|
+
message: "Service Unavailable"
|
|
787
|
+
},
|
|
788
|
+
{
|
|
789
|
+
code: 504,
|
|
790
|
+
message: "Gateway Timeout"
|
|
791
|
+
},
|
|
792
|
+
{
|
|
793
|
+
code: 505,
|
|
794
|
+
message: "HTTP Version Not Supported"
|
|
795
|
+
},
|
|
796
|
+
{
|
|
797
|
+
code: 506,
|
|
798
|
+
message: "Variant Also Negotiates"
|
|
799
|
+
},
|
|
800
|
+
{
|
|
801
|
+
code: 507,
|
|
802
|
+
message: "Insufficient Storage"
|
|
803
|
+
},
|
|
804
|
+
{
|
|
805
|
+
code: 508,
|
|
806
|
+
message: "Loop Detected"
|
|
807
|
+
},
|
|
808
|
+
{
|
|
809
|
+
code: 510,
|
|
810
|
+
message: "Not Extended"
|
|
811
|
+
},
|
|
812
|
+
{
|
|
813
|
+
code: 511,
|
|
814
|
+
message: "Network Authentication Required"
|
|
815
|
+
}
|
|
816
|
+
];
|
|
817
|
+
var statusSchema = {
|
|
818
|
+
description: "Return status code or random status code if more than one are given ",
|
|
819
|
+
tags: [
|
|
820
|
+
"Status Codes"
|
|
821
|
+
],
|
|
822
|
+
params: {
|
|
823
|
+
type: "object",
|
|
824
|
+
properties: {
|
|
825
|
+
code: {
|
|
826
|
+
type: "string",
|
|
827
|
+
description: "HTTP status code to be returned"
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
},
|
|
831
|
+
response: {
|
|
832
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
833
|
+
200: {
|
|
834
|
+
type: "object",
|
|
835
|
+
properties: {
|
|
836
|
+
status: {
|
|
837
|
+
type: "string"
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
};
|
|
843
|
+
var statusCodeRoute = /* @__PURE__ */ __name((fastify2) => {
|
|
844
|
+
const handler = /* @__PURE__ */ __name(async (request, reply) => {
|
|
845
|
+
let { code } = request.params;
|
|
846
|
+
if (!code || !statusCodes.map((status) => status.code).includes(Number(code))) {
|
|
847
|
+
code = statusCodes[randomInt(0, statusCodes.length)].code.toString();
|
|
848
|
+
}
|
|
849
|
+
await reply.code(Number(code)).send({
|
|
850
|
+
status: `Response with status code ${code}`
|
|
851
|
+
});
|
|
852
|
+
}, "handler");
|
|
853
|
+
fastify2.get("/status/:code?", {
|
|
854
|
+
schema: statusSchema
|
|
855
|
+
}, handler);
|
|
856
|
+
fastify2.post("/status/:code?", {
|
|
857
|
+
schema: statusSchema
|
|
858
|
+
}, handler);
|
|
859
|
+
fastify2.put("/status/:code?", {
|
|
860
|
+
schema: statusSchema
|
|
861
|
+
}, handler);
|
|
862
|
+
fastify2.patch("/status/:code?", {
|
|
863
|
+
schema: statusSchema
|
|
864
|
+
}, handler);
|
|
865
|
+
fastify2.delete("/status/:code?", {
|
|
866
|
+
schema: statusSchema
|
|
867
|
+
}, handler);
|
|
868
|
+
}, "statusCodeRoute");
|
|
869
|
+
|
|
870
|
+
// src/routes/response-inspection/cache.ts
|
|
871
|
+
var cacheGetSchema = {
|
|
872
|
+
description: "Handles cache validation and retrieval.",
|
|
873
|
+
tags: [
|
|
874
|
+
"Response Inspection"
|
|
875
|
+
],
|
|
876
|
+
response: {
|
|
877
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
878
|
+
200: {
|
|
879
|
+
type: "string",
|
|
880
|
+
description: "The cached content or resource."
|
|
881
|
+
},
|
|
882
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
883
|
+
304: {
|
|
884
|
+
type: "null",
|
|
885
|
+
description: "Indicates the resource has not been modified."
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
};
|
|
889
|
+
var cacheSetSchema = {
|
|
890
|
+
description: "Sets a Cache-Control header for n seconds.",
|
|
891
|
+
tags: [
|
|
892
|
+
"Response Inspection"
|
|
893
|
+
],
|
|
894
|
+
params: {
|
|
895
|
+
type: "object",
|
|
896
|
+
properties: {
|
|
897
|
+
value: {
|
|
898
|
+
type: "integer",
|
|
899
|
+
description: "Number of seconds to cache the resource."
|
|
900
|
+
}
|
|
901
|
+
},
|
|
902
|
+
required: [
|
|
903
|
+
"value"
|
|
904
|
+
]
|
|
905
|
+
},
|
|
906
|
+
response: {
|
|
907
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
908
|
+
200: {
|
|
909
|
+
type: "string",
|
|
910
|
+
description: "Confirmation message for setting cache."
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
};
|
|
914
|
+
var cacheRoutes = /* @__PURE__ */ __name((fastify2) => {
|
|
915
|
+
fastify2.get("/cache", {
|
|
916
|
+
schema: cacheGetSchema
|
|
917
|
+
}, async (request, reply) => {
|
|
918
|
+
const ifModifiedSince = request.headers["if-modified-since"];
|
|
919
|
+
const ifNoneMatch = request.headers["if-none-match"];
|
|
920
|
+
if (ifModifiedSince ?? ifNoneMatch) {
|
|
921
|
+
await reply.status(304).send();
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
await reply.send("Cache content or resource response here.");
|
|
925
|
+
});
|
|
926
|
+
fastify2.get("/cache/:value", {
|
|
927
|
+
schema: cacheSetSchema
|
|
928
|
+
}, async (request, reply) => {
|
|
929
|
+
const { value } = request.params;
|
|
930
|
+
await reply.header("Cache-Control", `max-age=${value}`).send(`Cache-Control set for ${value} seconds.`);
|
|
931
|
+
});
|
|
932
|
+
}, "cacheRoutes");
|
|
933
|
+
|
|
934
|
+
// src/routes/response-inspection/etag.ts
|
|
935
|
+
var etagSchema = {
|
|
936
|
+
description: "Handles ETag-based conditional requests.",
|
|
937
|
+
tags: [
|
|
938
|
+
"Response Inspection"
|
|
939
|
+
],
|
|
940
|
+
params: {
|
|
941
|
+
type: "object",
|
|
942
|
+
properties: {
|
|
943
|
+
etag: {
|
|
944
|
+
type: "string",
|
|
945
|
+
description: "The ETag value for the resource."
|
|
946
|
+
}
|
|
947
|
+
},
|
|
948
|
+
required: [
|
|
949
|
+
"etag"
|
|
950
|
+
]
|
|
951
|
+
},
|
|
952
|
+
response: {
|
|
953
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
954
|
+
200: {
|
|
955
|
+
type: "string",
|
|
956
|
+
description: "Resource content for matching ETag."
|
|
957
|
+
},
|
|
958
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
959
|
+
304: {
|
|
960
|
+
type: "null",
|
|
961
|
+
description: "Indicates the resource has not been modified."
|
|
962
|
+
},
|
|
963
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
964
|
+
412: {
|
|
965
|
+
type: "null",
|
|
966
|
+
description: "Indicates a precondition failed due to mismatched ETag."
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
};
|
|
970
|
+
var etagRoutes = /* @__PURE__ */ __name((fastify2) => {
|
|
971
|
+
fastify2.get("/etag/:etag", {
|
|
972
|
+
schema: etagSchema
|
|
973
|
+
}, async (request, reply) => {
|
|
974
|
+
const { etag } = request.params;
|
|
975
|
+
const ifNoneMatch = request.headers["if-none-match"];
|
|
976
|
+
const ifMatch = request.headers["if-match"];
|
|
977
|
+
if (ifNoneMatch === etag) {
|
|
978
|
+
await reply.status(304).send();
|
|
979
|
+
return;
|
|
980
|
+
}
|
|
981
|
+
if (ifMatch && ifMatch !== etag) {
|
|
982
|
+
await reply.status(412).send();
|
|
983
|
+
return;
|
|
984
|
+
}
|
|
985
|
+
await reply.header("ETag", etag).send("Resource content for matching ETag.");
|
|
986
|
+
});
|
|
987
|
+
}, "etagRoutes");
|
|
988
|
+
|
|
989
|
+
// src/routes/response-inspection/response-headers.ts
|
|
990
|
+
import { escape } from "html-escaper";
|
|
991
|
+
var responseHeadersSchema = {
|
|
992
|
+
description: "Returns a set of response headers based on the query string.",
|
|
993
|
+
tags: [
|
|
994
|
+
"Response Inspection"
|
|
995
|
+
],
|
|
996
|
+
querystring: {
|
|
997
|
+
type: "object",
|
|
998
|
+
additionalProperties: true,
|
|
999
|
+
description: "Freeform query string parameters to be added as response headers."
|
|
1000
|
+
},
|
|
1001
|
+
response: {
|
|
1002
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1003
|
+
200: {
|
|
1004
|
+
type: "object",
|
|
1005
|
+
additionalProperties: true,
|
|
1006
|
+
description: "Response headers as per query string parameters."
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
};
|
|
1010
|
+
var responseHeadersRoutes = /* @__PURE__ */ __name((fastify2) => {
|
|
1011
|
+
fastify2.get("/response-headers", {
|
|
1012
|
+
schema: responseHeadersSchema
|
|
1013
|
+
}, async (request, reply) => {
|
|
1014
|
+
const queryParameters = request.query;
|
|
1015
|
+
for (const [key, value] of Object.entries(queryParameters)) {
|
|
1016
|
+
reply.header(key, escape(value));
|
|
1017
|
+
}
|
|
1018
|
+
const cleanedResponse = Object.fromEntries(Object.entries(queryParameters).map(([key, value]) => [
|
|
1019
|
+
key,
|
|
1020
|
+
escape(value)
|
|
1021
|
+
]));
|
|
1022
|
+
await reply.send(cleanedResponse);
|
|
1023
|
+
});
|
|
1024
|
+
fastify2.post("/response-headers", {
|
|
1025
|
+
schema: responseHeadersSchema
|
|
1026
|
+
}, async (request, reply) => {
|
|
1027
|
+
const queryParameters = request.query ?? {};
|
|
1028
|
+
const body = request.body ?? {};
|
|
1029
|
+
for (const [key, value] of Object.entries(queryParameters)) {
|
|
1030
|
+
reply.header(key, escape(value));
|
|
1031
|
+
}
|
|
1032
|
+
for (const [key, value] of Object.entries(body)) {
|
|
1033
|
+
reply.header(key, escape(value));
|
|
1034
|
+
}
|
|
1035
|
+
const cleanedResponse = Object.fromEntries(Object.entries({
|
|
1036
|
+
...queryParameters,
|
|
1037
|
+
...body
|
|
1038
|
+
}).map(([key, value]) => [
|
|
1039
|
+
key,
|
|
1040
|
+
escape(value)
|
|
1041
|
+
]));
|
|
1042
|
+
await reply.send(cleanedResponse);
|
|
1043
|
+
});
|
|
1044
|
+
}, "responseHeadersRoutes");
|
|
1045
|
+
|
|
1046
|
+
// src/index.ts
|
|
1047
|
+
var fastify = Fastify(fastifyConfig);
|
|
14
1048
|
await fastify.register(fastifyStatic, {
|
|
15
|
-
|
|
1049
|
+
root: path.resolve("./node_modules/@scalar/api-reference/dist"),
|
|
1050
|
+
prefix: "/scalar"
|
|
16
1051
|
});
|
|
17
|
-
|
|
1052
|
+
await fastify.register(fastifyStatic, {
|
|
1053
|
+
root: path.resolve("./public"),
|
|
1054
|
+
decorateReply: false
|
|
1055
|
+
});
|
|
1056
|
+
await fastify.register(fastifyHelmet);
|
|
18
1057
|
await fastify.register(fastifySwagger, fastifySwaggerConfig);
|
|
19
|
-
// Register Swagger UI
|
|
20
1058
|
await registerSwaggerUi(fastify);
|
|
21
|
-
// Register the index / home page route
|
|
22
1059
|
await fastify.register(indexRoute);
|
|
23
|
-
// Register the HTTP method routes
|
|
24
1060
|
await fastify.register(getRoute);
|
|
25
1061
|
await fastify.register(postRoute);
|
|
26
1062
|
await fastify.register(deleteRoute);
|
|
27
1063
|
await fastify.register(putRoute);
|
|
28
1064
|
await fastify.register(patchRoute);
|
|
29
|
-
|
|
1065
|
+
await fastify.register(statusCodeRoute);
|
|
30
1066
|
await fastify.register(ipRoute);
|
|
31
1067
|
await fastify.register(headersRoute);
|
|
32
1068
|
await fastify.register(userAgentRoute);
|
|
33
|
-
|
|
34
|
-
await fastify.register(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
1069
|
+
await fastify.register(cacheRoutes);
|
|
1070
|
+
await fastify.register(etagRoutes);
|
|
1071
|
+
await fastify.register(responseHeadersRoutes);
|
|
1072
|
+
var start = /* @__PURE__ */ __name(async () => {
|
|
1073
|
+
try {
|
|
1074
|
+
let port = 3e3;
|
|
1075
|
+
if (process.env.PORT) {
|
|
1076
|
+
port = Number.parseInt(process.env.PORT, 10);
|
|
40
1077
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// eslint-disable-next-line unicorn/no-process-exit
|
|
45
|
-
process.exit(1);
|
|
1078
|
+
let host = "0.0.0.0";
|
|
1079
|
+
if (process.env.HOST) {
|
|
1080
|
+
host = process.env.HOST;
|
|
46
1081
|
}
|
|
47
|
-
|
|
1082
|
+
await fastify.listen({
|
|
1083
|
+
port,
|
|
1084
|
+
host
|
|
1085
|
+
});
|
|
1086
|
+
} catch (error) {
|
|
1087
|
+
fastify.log.error(error);
|
|
1088
|
+
process.exit(1);
|
|
1089
|
+
}
|
|
1090
|
+
}, "start");
|
|
48
1091
|
await start();
|
|
1092
|
+
export {
|
|
1093
|
+
start
|
|
1094
|
+
};
|