@jaredwray/mockhttp 0.0.1 → 0.1.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/dist/index.js CHANGED
@@ -1,48 +1,913 @@
1
- import process from 'node:process';
2
- import path from 'node:path';
3
- import Fastify from 'fastify';
4
- import fastifyStatic from '@fastify/static';
5
- import { fastifySwagger } from '@fastify/swagger';
6
- import { indexRoute } from './routes/index-route.js';
7
- import { fastifyConfig } from './fastify-config.js';
8
- import { fastifySwaggerConfig, registerSwaggerUi } from './swagger.js';
9
- import { ipRoute, headersRoute, userAgentRoute } from './routes/request-inspection/index.js';
10
- import { getRoute, postRoute, deleteRoute, putRoute, patchRoute, } from './routes/http-methods/index.js';
11
- import { statusCodeRoute } from './routes/status-codes/index.js';
12
- // eslint-disable-next-line new-cap
13
- const fastify = Fastify(fastifyConfig);
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.1.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
+ "@vitest/coverage-v8": "^2.1.8",
142
+ rimraf: "^6.0.1",
143
+ tsup: "^8.3.5",
144
+ tsx: "^4.19.2",
145
+ typescript: "^5.7.2",
146
+ vitest: "^2.1.8",
147
+ xo: "^0.60.0"
148
+ },
149
+ dependencies: {
150
+ "@fastify/helmet": "^13.0.0",
151
+ "@fastify/static": "^8.0.3",
152
+ "@fastify/swagger": "^9.4.0",
153
+ "@fastify/swagger-ui": "^5.2.0",
154
+ "@scalar/api-reference": "^1.25.80",
155
+ fastify: "^5.1.0",
156
+ pino: "^9.5.0",
157
+ "pino-pretty": "^13.0.0"
158
+ },
159
+ files: [
160
+ "dist",
161
+ "public",
162
+ "LICENCE"
163
+ ]
164
+ };
165
+
166
+ // src/swagger.ts
167
+ var fastifySwaggerConfig = {
168
+ openapi: {
169
+ info: {
170
+ title: "Mock HTTP API",
171
+ description: "A replacement for httpbin built using Fastify and Typescript",
172
+ version: package_default.version
173
+ },
174
+ consumes: [
175
+ "application/json"
176
+ ],
177
+ produces: [
178
+ "application/json"
179
+ ]
180
+ }
181
+ };
182
+ var registerSwaggerUi = /* @__PURE__ */ __name(async (fastify2) => {
183
+ await fastify2.register(fastifySwaggerUi, {
184
+ routePrefix: "/docs",
185
+ uiConfig: {
186
+ docExpansion: "none",
187
+ deepLinking: false
188
+ },
189
+ uiHooks: {
190
+ /* c8 ignore next 6 */
191
+ onRequest(_request, _reply, next) {
192
+ next();
193
+ },
194
+ preHandler(_request, _reply, next) {
195
+ next();
196
+ }
197
+ },
198
+ // eslint-disable-next-line @typescript-eslint/naming-convention
199
+ staticCSP: true,
200
+ transformSpecification: /* @__PURE__ */ __name((swaggerObject, _request, _reply) => swaggerObject, "transformSpecification"),
201
+ transformSpecificationClone: true
202
+ });
203
+ }, "registerSwaggerUi");
204
+
205
+ // src/routes/request-inspection/ip.ts
206
+ var ipSchema = {
207
+ description: "Returns the IP address of the client",
208
+ tags: [
209
+ "Request Inspection"
210
+ ],
211
+ response: {
212
+ // eslint-disable-next-line @typescript-eslint/naming-convention
213
+ 200: {
214
+ type: "object",
215
+ properties: {
216
+ ip: {
217
+ type: "string",
218
+ description: "The IP address of the client"
219
+ }
220
+ },
221
+ required: [
222
+ "ip"
223
+ ]
224
+ }
225
+ }
226
+ };
227
+ var ipRoute = /* @__PURE__ */ __name((fastify2) => {
228
+ fastify2.get("/ip", {
229
+ schema: ipSchema
230
+ }, async (request) => {
231
+ const cloudflareIp = request.headers["cf-connecting-ip"];
232
+ const forwardedIp = request.headers["x-forwarded-for"];
233
+ const remoteIp = request.ip;
234
+ const ip = cloudflareIp ?? (typeof forwardedIp === "string" ? forwardedIp.split(",")[0].trim() : remoteIp);
235
+ return {
236
+ ip
237
+ };
238
+ });
239
+ }, "ipRoute");
240
+
241
+ // src/routes/request-inspection/headers.ts
242
+ var headersSchema = {
243
+ description: "Returns all headers of the client request",
244
+ tags: [
245
+ "Request Inspection"
246
+ ],
247
+ response: {
248
+ // eslint-disable-next-line @typescript-eslint/naming-convention
249
+ 200: {
250
+ type: "object",
251
+ properties: {
252
+ headers: {
253
+ type: "object",
254
+ additionalProperties: {
255
+ type: "string"
256
+ },
257
+ description: "All headers of the client request"
258
+ }
259
+ },
260
+ required: [
261
+ "headers"
262
+ ]
263
+ }
264
+ }
265
+ };
266
+ var headersRoute = /* @__PURE__ */ __name((fastify2) => {
267
+ fastify2.get("/headers", {
268
+ schema: headersSchema
269
+ }, async (request) => {
270
+ const headers = request.headers;
271
+ return {
272
+ headers
273
+ };
274
+ });
275
+ }, "headersRoute");
276
+
277
+ // src/routes/request-inspection/user-agent.ts
278
+ var userAgentSchema = {
279
+ description: "Returns the User-Agent header of the client request",
280
+ tags: [
281
+ "Request Inspection"
282
+ ],
283
+ response: {
284
+ // eslint-disable-next-line @typescript-eslint/naming-convention
285
+ 200: {
286
+ type: "object",
287
+ properties: {
288
+ userAgent: {
289
+ type: "string",
290
+ description: "The User-Agent header of the client request"
291
+ }
292
+ },
293
+ required: [
294
+ "userAgent"
295
+ ]
296
+ }
297
+ }
298
+ };
299
+ var userAgentRoute = /* @__PURE__ */ __name((fastify2) => {
300
+ fastify2.get("/user-agent", {
301
+ schema: userAgentSchema
302
+ }, async (request) => {
303
+ const userAgent = request.headers["user-agent"];
304
+ return {
305
+ userAgent
306
+ };
307
+ });
308
+ }, "userAgentRoute");
309
+
310
+ // src/routes/http-methods/get.ts
311
+ var getSchema = {
312
+ description: "Returns request information for GET requests",
313
+ tags: [
314
+ "HTTP Methods"
315
+ ],
316
+ querystring: {
317
+ type: "object",
318
+ additionalProperties: true,
319
+ properties: {},
320
+ description: "Query parameters sent in the request"
321
+ },
322
+ headers: {
323
+ type: "object",
324
+ additionalProperties: true,
325
+ properties: {},
326
+ description: "Headers sent in the request"
327
+ },
328
+ response: {
329
+ // eslint-disable-next-line @typescript-eslint/naming-convention
330
+ 200: {
331
+ type: "object",
332
+ properties: {
333
+ method: {
334
+ type: "string"
335
+ },
336
+ headers: {
337
+ type: "object",
338
+ additionalProperties: {
339
+ type: "string"
340
+ }
341
+ },
342
+ queryParams: {
343
+ type: "object",
344
+ additionalProperties: {
345
+ type: "string"
346
+ }
347
+ }
348
+ },
349
+ required: [
350
+ "method",
351
+ "headers",
352
+ "queryParams"
353
+ ]
354
+ }
355
+ }
356
+ };
357
+ var getRoute = /* @__PURE__ */ __name((fastify2) => {
358
+ fastify2.get("/get", {
359
+ schema: getSchema
360
+ }, async (request, _reply) => ({
361
+ method: "GET",
362
+ headers: request.headers,
363
+ queryParams: request.query
364
+ }));
365
+ }, "getRoute");
366
+
367
+ // src/routes/http-methods/post.ts
368
+ var postSchema = {
369
+ description: "Handles a POST request and returns request information",
370
+ tags: [
371
+ "HTTP Methods"
372
+ ],
373
+ body: {
374
+ type: "object",
375
+ additionalProperties: true,
376
+ description: "The body of the POST request"
377
+ },
378
+ response: {
379
+ // eslint-disable-next-line @typescript-eslint/naming-convention
380
+ 200: {
381
+ type: "object",
382
+ properties: {
383
+ method: {
384
+ type: "string"
385
+ },
386
+ headers: {
387
+ type: "object",
388
+ additionalProperties: {
389
+ type: "string"
390
+ }
391
+ },
392
+ body: {
393
+ type: "object",
394
+ additionalProperties: true
395
+ }
396
+ },
397
+ required: [
398
+ "method",
399
+ "headers",
400
+ "body"
401
+ ]
402
+ }
403
+ }
404
+ };
405
+ var postRoute = /* @__PURE__ */ __name((fastify2) => {
406
+ fastify2.post("/post", {
407
+ schema: postSchema
408
+ }, async (request) => ({
409
+ method: "POST",
410
+ headers: request.headers,
411
+ body: request.body
412
+ }));
413
+ }, "postRoute");
414
+
415
+ // src/routes/http-methods/delete.ts
416
+ var deleteSchema = {
417
+ description: "Handles a DELETE request and returns request information",
418
+ tags: [
419
+ "HTTP Methods"
420
+ ],
421
+ body: {
422
+ type: "object",
423
+ additionalProperties: true,
424
+ description: "The body of the DELETE request"
425
+ },
426
+ response: {
427
+ // eslint-disable-next-line @typescript-eslint/naming-convention
428
+ 200: {
429
+ type: "object",
430
+ properties: {
431
+ method: {
432
+ type: "string"
433
+ },
434
+ headers: {
435
+ type: "object",
436
+ additionalProperties: {
437
+ type: "string"
438
+ }
439
+ },
440
+ body: {
441
+ type: "object",
442
+ additionalProperties: true
443
+ }
444
+ },
445
+ required: [
446
+ "method",
447
+ "headers",
448
+ "body"
449
+ ]
450
+ }
451
+ }
452
+ };
453
+ var deleteRoute = /* @__PURE__ */ __name((fastify2) => {
454
+ fastify2.delete("/delete", {
455
+ schema: deleteSchema
456
+ }, async (request) => ({
457
+ method: "DELETE",
458
+ headers: request.headers,
459
+ body: request.body
460
+ }));
461
+ }, "deleteRoute");
462
+
463
+ // src/routes/http-methods/put.ts
464
+ var putSchema = {
465
+ description: "Handles a PUT request and returns request information",
466
+ tags: [
467
+ "HTTP Methods"
468
+ ],
469
+ body: {
470
+ type: "object",
471
+ additionalProperties: true,
472
+ description: "The body of the PUT request"
473
+ },
474
+ response: {
475
+ // eslint-disable-next-line @typescript-eslint/naming-convention
476
+ 200: {
477
+ type: "object",
478
+ properties: {
479
+ method: {
480
+ type: "string"
481
+ },
482
+ headers: {
483
+ type: "object",
484
+ additionalProperties: {
485
+ type: "string"
486
+ }
487
+ },
488
+ body: {
489
+ type: "object",
490
+ additionalProperties: true
491
+ }
492
+ },
493
+ required: [
494
+ "method",
495
+ "headers",
496
+ "body"
497
+ ]
498
+ }
499
+ }
500
+ };
501
+ var putRoute = /* @__PURE__ */ __name((fastify2) => {
502
+ fastify2.put("/put", {
503
+ schema: putSchema
504
+ }, async (request) => ({
505
+ method: "PUT",
506
+ headers: request.headers,
507
+ body: request.body
508
+ }));
509
+ }, "putRoute");
510
+
511
+ // src/routes/http-methods/patch.ts
512
+ var patchSchema = {
513
+ description: "Handles a PATCH request and returns request information",
514
+ tags: [
515
+ "HTTP Methods"
516
+ ],
517
+ body: {
518
+ type: "object",
519
+ additionalProperties: true,
520
+ description: "The body of the PATCH request"
521
+ },
522
+ response: {
523
+ // eslint-disable-next-line @typescript-eslint/naming-convention
524
+ 200: {
525
+ type: "object",
526
+ properties: {
527
+ method: {
528
+ type: "string"
529
+ },
530
+ headers: {
531
+ type: "object",
532
+ additionalProperties: {
533
+ type: "string"
534
+ }
535
+ },
536
+ body: {
537
+ type: "object",
538
+ additionalProperties: true
539
+ }
540
+ },
541
+ required: [
542
+ "method",
543
+ "headers",
544
+ "body"
545
+ ]
546
+ }
547
+ }
548
+ };
549
+ var patchRoute = /* @__PURE__ */ __name((fastify2) => {
550
+ fastify2.patch("/patch", {
551
+ schema: patchSchema
552
+ }, async (request) => ({
553
+ method: "PATCH",
554
+ headers: request.headers,
555
+ body: request.body
556
+ }));
557
+ }, "patchRoute");
558
+
559
+ // src/routes/status-codes/index.ts
560
+ import { randomInt } from "node:crypto";
561
+ var statusCodes = [
562
+ {
563
+ code: 100,
564
+ message: "Continue"
565
+ },
566
+ {
567
+ code: 101,
568
+ message: "Switching Protocols"
569
+ },
570
+ {
571
+ code: 102,
572
+ message: "Processing"
573
+ },
574
+ {
575
+ code: 103,
576
+ message: "Early Hints"
577
+ },
578
+ {
579
+ code: 200,
580
+ message: "OK"
581
+ },
582
+ {
583
+ code: 201,
584
+ message: "Created"
585
+ },
586
+ {
587
+ code: 202,
588
+ message: "Accepted"
589
+ },
590
+ {
591
+ code: 203,
592
+ message: "Non-Authoritative Information"
593
+ },
594
+ {
595
+ code: 204,
596
+ message: "No Content"
597
+ },
598
+ {
599
+ code: 205,
600
+ message: "Reset Content"
601
+ },
602
+ {
603
+ code: 206,
604
+ message: "Partial Content"
605
+ },
606
+ {
607
+ code: 207,
608
+ message: "Multi-Status"
609
+ },
610
+ {
611
+ code: 208,
612
+ message: "Already Reported"
613
+ },
614
+ {
615
+ code: 226,
616
+ message: "IM Used"
617
+ },
618
+ {
619
+ code: 300,
620
+ message: "Multiple Choices"
621
+ },
622
+ {
623
+ code: 301,
624
+ message: "Moved Permanently"
625
+ },
626
+ {
627
+ code: 302,
628
+ message: "Found"
629
+ },
630
+ {
631
+ code: 303,
632
+ message: "See Other"
633
+ },
634
+ {
635
+ code: 304,
636
+ message: "Not Modified"
637
+ },
638
+ {
639
+ code: 305,
640
+ message: "Use Proxy"
641
+ },
642
+ {
643
+ code: 306,
644
+ message: "Switch Proxy"
645
+ },
646
+ {
647
+ code: 307,
648
+ message: "Temporary Redirect"
649
+ },
650
+ {
651
+ code: 308,
652
+ message: "Permanent Redirect"
653
+ },
654
+ {
655
+ code: 400,
656
+ message: "Bad Request"
657
+ },
658
+ {
659
+ code: 401,
660
+ message: "Unauthorized"
661
+ },
662
+ {
663
+ code: 402,
664
+ message: "Payment Required"
665
+ },
666
+ {
667
+ code: 403,
668
+ message: "Forbidden"
669
+ },
670
+ {
671
+ code: 404,
672
+ message: "Not Found"
673
+ },
674
+ {
675
+ code: 405,
676
+ message: "Method Not Allowed"
677
+ },
678
+ {
679
+ code: 406,
680
+ message: "Not Acceptable"
681
+ },
682
+ {
683
+ code: 407,
684
+ message: "Proxy Authentication Required"
685
+ },
686
+ {
687
+ code: 408,
688
+ message: "Request Timeout"
689
+ },
690
+ {
691
+ code: 409,
692
+ message: "Conflict"
693
+ },
694
+ {
695
+ code: 410,
696
+ message: "Gone"
697
+ },
698
+ {
699
+ code: 411,
700
+ message: "Length Required"
701
+ },
702
+ {
703
+ code: 412,
704
+ message: "Precondition Failed"
705
+ },
706
+ {
707
+ code: 413,
708
+ message: "Payload Too Large"
709
+ },
710
+ {
711
+ code: 414,
712
+ message: "URI Too Long"
713
+ },
714
+ {
715
+ code: 415,
716
+ message: "Unsupported Media Type"
717
+ },
718
+ {
719
+ code: 416,
720
+ message: "Range Not Satisfiable"
721
+ },
722
+ {
723
+ code: 417,
724
+ message: "Expectation Failed"
725
+ },
726
+ {
727
+ code: 418,
728
+ message: "I'm a teapot"
729
+ },
730
+ {
731
+ code: 421,
732
+ message: "Misdirected Request"
733
+ },
734
+ {
735
+ code: 422,
736
+ message: "Unprocessable Entity"
737
+ },
738
+ {
739
+ code: 423,
740
+ message: "Locked"
741
+ },
742
+ {
743
+ code: 424,
744
+ message: "Failed Dependency"
745
+ },
746
+ {
747
+ code: 425,
748
+ message: "Too Early"
749
+ },
750
+ {
751
+ code: 426,
752
+ message: "Upgrade Required"
753
+ },
754
+ {
755
+ code: 428,
756
+ message: "Precondition Required"
757
+ },
758
+ {
759
+ code: 429,
760
+ message: "Too Many Requests"
761
+ },
762
+ {
763
+ code: 431,
764
+ message: "Request Header Fields Too Large"
765
+ },
766
+ {
767
+ code: 451,
768
+ message: "Unavailable For Legal Reasons"
769
+ },
770
+ {
771
+ code: 500,
772
+ message: "Internal Server Error"
773
+ },
774
+ {
775
+ code: 501,
776
+ message: "Not Implemented"
777
+ },
778
+ {
779
+ code: 502,
780
+ message: "Bad Gateway"
781
+ },
782
+ {
783
+ code: 503,
784
+ message: "Service Unavailable"
785
+ },
786
+ {
787
+ code: 504,
788
+ message: "Gateway Timeout"
789
+ },
790
+ {
791
+ code: 505,
792
+ message: "HTTP Version Not Supported"
793
+ },
794
+ {
795
+ code: 506,
796
+ message: "Variant Also Negotiates"
797
+ },
798
+ {
799
+ code: 507,
800
+ message: "Insufficient Storage"
801
+ },
802
+ {
803
+ code: 508,
804
+ message: "Loop Detected"
805
+ },
806
+ {
807
+ code: 510,
808
+ message: "Not Extended"
809
+ },
810
+ {
811
+ code: 511,
812
+ message: "Network Authentication Required"
813
+ }
814
+ ];
815
+ var statusSchema = {
816
+ description: "Return status code or random status code if more than one are given ",
817
+ tags: [
818
+ "Status Codes"
819
+ ],
820
+ params: {
821
+ type: "object",
822
+ properties: {
823
+ code: {
824
+ type: "string",
825
+ description: "HTTP status code to be returned"
826
+ }
827
+ }
828
+ },
829
+ response: {
830
+ // eslint-disable-next-line @typescript-eslint/naming-convention
831
+ 200: {
832
+ type: "object",
833
+ properties: {
834
+ status: {
835
+ type: "string"
836
+ }
837
+ }
838
+ }
839
+ }
840
+ };
841
+ var statusCodeRoute = /* @__PURE__ */ __name((fastify2) => {
842
+ const handler = /* @__PURE__ */ __name(async (request, reply) => {
843
+ let { code } = request.params;
844
+ if (!code || !statusCodes.map((status) => status.code).includes(Number(code))) {
845
+ code = statusCodes[randomInt(0, statusCodes.length)].code.toString();
846
+ }
847
+ await reply.code(Number(code)).send({
848
+ status: `Response with status code ${code}`
849
+ });
850
+ }, "handler");
851
+ fastify2.get("/status/:code?", {
852
+ schema: statusSchema
853
+ }, handler);
854
+ fastify2.post("/status/:code?", {
855
+ schema: statusSchema
856
+ }, handler);
857
+ fastify2.put("/status/:code?", {
858
+ schema: statusSchema
859
+ }, handler);
860
+ fastify2.patch("/status/:code?", {
861
+ schema: statusSchema
862
+ }, handler);
863
+ fastify2.delete("/status/:code?", {
864
+ schema: statusSchema
865
+ }, handler);
866
+ }, "statusCodeRoute");
867
+
868
+ // src/index.ts
869
+ var fastify = Fastify(fastifyConfig);
14
870
  await fastify.register(fastifyStatic, {
15
- root: path.resolve('./public'),
871
+ root: path.resolve("./node_modules/@scalar/api-reference/dist"),
872
+ prefix: "/scalar"
16
873
  });
17
- // Set up Swagger for API documentation
874
+ await fastify.register(fastifyStatic, {
875
+ root: path.resolve("./public"),
876
+ decorateReply: false
877
+ });
878
+ await fastify.register(fastifyHelmet);
18
879
  await fastify.register(fastifySwagger, fastifySwaggerConfig);
19
- // Register Swagger UI
20
880
  await registerSwaggerUi(fastify);
21
- // Register the index / home page route
22
881
  await fastify.register(indexRoute);
23
- // Register the HTTP method routes
24
882
  await fastify.register(getRoute);
25
883
  await fastify.register(postRoute);
26
884
  await fastify.register(deleteRoute);
27
885
  await fastify.register(putRoute);
28
886
  await fastify.register(patchRoute);
29
- // Register the request inspection routes
30
887
  await fastify.register(ipRoute);
31
888
  await fastify.register(headersRoute);
32
889
  await fastify.register(userAgentRoute);
33
- // Register the status code routes
34
890
  await fastify.register(statusCodeRoute);
35
- // Start the Fastify server
36
- export const start = async () => {
37
- try {
38
- await fastify.listen({ port: 3000, host: '127.0.0.1' });
39
- fastify.log.info('Server is running at http://localhost:3000');
891
+ var start = /* @__PURE__ */ __name(async () => {
892
+ try {
893
+ let port = 3e3;
894
+ if (process.env.PORT) {
895
+ port = Number.parseInt(process.env.PORT, 10);
40
896
  }
41
- catch (error) {
42
- /* c8 ignore next 4 */
43
- fastify.log.error(error);
44
- // eslint-disable-next-line unicorn/no-process-exit
45
- process.exit(1);
897
+ let host = "0.0.0.0";
898
+ if (process.env.HOST) {
899
+ host = process.env.HOST;
46
900
  }
47
- };
901
+ await fastify.listen({
902
+ port,
903
+ host
904
+ });
905
+ } catch (error) {
906
+ fastify.log.error(error);
907
+ process.exit(1);
908
+ }
909
+ }, "start");
48
910
  await start();
911
+ export {
912
+ start
913
+ };