@jaredwray/mockhttp 1.9.0 → 2.0.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.
Files changed (64) hide show
  1. package/README.md +29 -7
  2. package/dist/index.d.mts +90 -11
  3. package/dist/index.mjs +202 -240
  4. package/package.json +17 -13
  5. package/site/dist/api/index.html +17983 -0
  6. package/site/dist/api/swagger.json +5487 -0
  7. package/site/dist/changelog/index.html +767 -0
  8. package/site/dist/changelog/page/2/index.html +578 -0
  9. package/site/dist/changelog/v0-1-0/index.html +453 -0
  10. package/site/dist/changelog/v0-2-0/index.html +437 -0
  11. package/site/dist/changelog/v0-2-1/index.html +438 -0
  12. package/site/dist/changelog/v0-2-2/index.html +436 -0
  13. package/site/dist/changelog/v0-2-3/index.html +440 -0
  14. package/site/dist/changelog/v0-3-0/index.html +443 -0
  15. package/site/dist/changelog/v0-4-0/index.html +437 -0
  16. package/site/dist/changelog/v0-4-1/index.html +441 -0
  17. package/site/dist/changelog/v0-4-2/index.html +446 -0
  18. package/site/dist/changelog/v0-4-3/index.html +437 -0
  19. package/site/dist/changelog/v0-5-0/index.html +443 -0
  20. package/site/dist/changelog/v0-6-0/index.html +444 -0
  21. package/site/dist/changelog/v0-6-1/index.html +441 -0
  22. package/site/dist/changelog/v0-7-0/index.html +445 -0
  23. package/site/dist/changelog/v0-8-0/index.html +440 -0
  24. package/site/dist/changelog/v0-9-0/index.html +437 -0
  25. package/site/dist/changelog/v1-0-0/index.html +446 -0
  26. package/site/dist/changelog/v1-0-1/index.html +437 -0
  27. package/site/dist/changelog/v1-1-0/index.html +445 -0
  28. package/site/dist/changelog/v1-2-0/index.html +443 -0
  29. package/site/dist/changelog/v1-3-0/index.html +448 -0
  30. package/site/dist/changelog/v1-4-0/index.html +445 -0
  31. package/site/dist/changelog/v1-5-0/index.html +439 -0
  32. package/site/dist/changelog/v1-5-1/index.html +443 -0
  33. package/site/dist/changelog/v1-6-0/index.html +467 -0
  34. package/site/dist/changelog/v1-7-0/index.html +462 -0
  35. package/site/dist/changelog/v1-8-0/index.html +481 -0
  36. package/site/dist/changelog/v1-8-1/index.html +457 -0
  37. package/site/dist/changelog/v1-9-0/index.html +495 -0
  38. package/site/dist/changelog/v2-0-0/index.html +500 -0
  39. package/site/dist/changelog-latest.json +269 -0
  40. package/site/dist/changelog.json +399 -0
  41. package/site/dist/css/api.css +1113 -0
  42. package/site/dist/css/highlight/highlight.min.js +1433 -0
  43. package/site/dist/css/highlight/styles/base16/docula.css +123 -0
  44. package/site/dist/css/home.css +133 -0
  45. package/site/dist/css/styles.css +1227 -0
  46. package/site/dist/css/variables.css +32 -0
  47. package/site/dist/docs/bins/index.html +942 -0
  48. package/site/dist/docs/configuration/index.html +771 -0
  49. package/site/dist/docs/hosted/index.html +544 -0
  50. package/site/dist/docs/https/index.html +758 -0
  51. package/site/dist/docs/index.html +601 -0
  52. package/site/dist/docs/library/index.html +780 -0
  53. package/site/dist/docs/taps/index.html +708 -0
  54. package/site/dist/favicon.svg +14 -0
  55. package/site/dist/feed.xml +1 -0
  56. package/site/dist/index.html +601 -0
  57. package/site/dist/js/api.js +363 -0
  58. package/site/dist/js/search.js +436 -0
  59. package/site/dist/llms-full.txt +7415 -0
  60. package/site/dist/llms.txt +40 -0
  61. package/site/dist/logo.svg +21 -0
  62. package/site/dist/robots.txt +2 -0
  63. package/site/dist/search-index.json +1 -0
  64. package/site/dist/sitemap.xml +1 -0
package/README.md CHANGED
@@ -17,8 +17,8 @@ A simple HTTP server that can be used to mock HTTP responses for testing purpose
17
17
  * `@fastify/helmet` built in by default
18
18
  * Built with `nodejs`, `typescript`, and `fastify`
19
19
  * Deploy via `docker` or `nodejs`
20
- * Global deployment via [mockhttp.org](https://mockhttp.org) (free service)
21
- * Better API documentation and examples
20
+ * Free hosted service at [mockhttp.org](https://mockhttp.org), running on a Cloudflare Worker
21
+ * Documentation site and interactive OpenAPI reference (Docula)
22
22
  * Auto detect the port that is not in use
23
23
  * Maintained and updated regularly!
24
24
 
@@ -998,9 +998,13 @@ new MockHttp(options?)
998
998
  - `host?`: string - The host to listen on (default: '0.0.0.0')
999
999
  - `autoDetectPort?`: boolean - Auto-detect next available port if in use (default: true)
1000
1000
  - `helmet?`: boolean - Use Helmet for security headers (default: true)
1001
- - `apiDocs?`: boolean - Enable Swagger API documentation (default: true)
1001
+ - `apiDocs?`: boolean - Serve the Docula documentation site and OpenAPI spec (default: true)
1002
+ - `siteDistPath?`: string - Path to the built Docula site (default: the package `site/dist` directory)
1002
1003
  - `rateLimit?`: RateLimitPluginOptions - Configure rate limiting (default: 1000 req/min, localhost excluded)
1003
1004
  - `logging?`: boolean - Enable logging (default: true)
1005
+ - `staticFiles?`: boolean - Serve files from the package `public/` directory (default: true)
1006
+ - `pluginTimeout?`: number - Fastify plugin boot timeout in milliseconds; `0` disables it (default: Fastify's timeout)
1007
+ - `startBins?`: boolean - Start the request-bin cleanup timer during `initialize()` (default: true)
1004
1008
  - `httpBin?`: HttpBinOptions - Configure which httpbin routes to enable
1005
1009
  - `httpMethods?`: boolean - Enable HTTP method routes (default: true)
1006
1010
  - `redirects?`: boolean - Enable redirect routes (default: true)
@@ -1024,8 +1028,12 @@ new MockHttp(options?)
1024
1028
  - `host`: string - Get/set the server host
1025
1029
  - `autoDetectPort`: boolean - Get/set auto-detect port behavior
1026
1030
  - `helmet`: boolean - Get/set Helmet security headers
1027
- - `apiDocs`: boolean - Get/set API documentation
1031
+ - `apiDocs`: boolean - Get/set whether the documentation site and OpenAPI spec are served
1032
+ - `siteDistPath`: string - Get/set the path to the built Docula site
1028
1033
  - `logging`: boolean - Get/set logging enabled state
1034
+ - `staticFiles`: boolean - Get/set whether files from `public/` are served
1035
+ - `pluginTimeout`: number | undefined - Get/set Fastify plugin boot timeout
1036
+ - `startBins`: boolean - Get/set whether bin cleanup starts during `initialize()`
1029
1037
  - `rateLimit`: RateLimitPluginOptions | undefined - Get/set rate limiting options
1030
1038
  - `httpBin`: HttpBinOptions - Get/set httpbin route options
1031
1039
  - `https`: HttpsOptions | undefined - Get/set HTTPS configuration
@@ -1038,6 +1046,10 @@ new MockHttp(options?)
1038
1046
 
1039
1047
  ### Methods
1040
1048
 
1049
+ #### `async initialize()`
1050
+
1051
+ Register plugins and routes without listening. Use `server.inject()` afterwards, or call `start()` to bind a port.
1052
+
1041
1053
  #### `async start()`
1042
1054
 
1043
1055
  Start the Fastify server. If already running, it will be closed and restarted.
@@ -1054,7 +1066,15 @@ Detect the next available port.
1054
1066
 
1055
1067
  #### `async registerApiDocs(fastifyInstance?)`
1056
1068
 
1057
- Register Swagger API documentation routes.
1069
+ Register OpenAPI generation and the Docula documentation site.
1070
+
1071
+ #### `async registerSwagger(fastifyInstance?)`
1072
+
1073
+ Register `@fastify/swagger` and the live `/openapi.json` spec route.
1074
+
1075
+ #### `async registerSite(fastifyInstance?)`
1076
+
1077
+ Serve the built Docula site from `siteDistPath` when the directory exists.
1058
1078
 
1059
1079
  #### `async registerHttpMethods(fastifyInstance?)`
1060
1080
 
@@ -1210,9 +1230,11 @@ A getter that returns whether there are any active injections.
1210
1230
 
1211
1231
  **Returns:** boolean - `true` if there are active injections, `false` otherwise
1212
1232
 
1213
- # About mockhttp.org
1233
+ # About mockhttp.org
1234
+
1235
+ [mockhttp.org](https://mockhttp.org) is a free hosted instance of this codebase for testing. It runs on a [Cloudflare Worker](https://developers.cloudflare.com/workers/) (no containers): documentation is served from Workers Assets, and mock APIs such as `/get` and `/post` run in the Worker. The service is globally available and rate-limited (1000 requests per minute per IP) to prevent abuse.
1214
1236
 
1215
- [mockhttp.org](https://mockhttp.org) is a free service that runs this codebase and allows you to use it for testing purposes. It is a simple way to mock HTTP responses for testing purposes. It is globally available has some limitations on it to prevent abuse such as requests per second. It is ran via [Cloudflare](https://cloudflare.com) and [Google Cloud Run](https://cloud.google.com/run/) across 7 regions globally and can do millions of requests per second.
1237
+ Getting Started is served at `/` and `/docs`, other guides at `/docs/...`, and the interactive HTTP API reference at `/api`. Mock endpoints such as `/get` and `/post` are unchanged.
1216
1238
 
1217
1239
  # Contributing
1218
1240
 
package/dist/index.d.mts CHANGED
@@ -83,7 +83,7 @@ interface BinStore {
83
83
  * In-memory implementation of {@link BinStore} backed by two Maps. State is
84
84
  * lost when the process exits.
85
85
  */
86
- declare class InMemoryBinStore implements BinStore {
86
+ export declare class InMemoryBinStore implements BinStore {
87
87
  private readonly _bins;
88
88
  private readonly _requests;
89
89
  createBin(bin: Bin): void;
@@ -119,7 +119,7 @@ type BinManagerOptions = {
119
119
  * Manages request bins: ephemeral URL endpoints that capture incoming HTTP
120
120
  * requests so they can be inspected later.
121
121
  */
122
- declare class BinManager {
122
+ export declare class BinManager {
123
123
  private readonly _store;
124
124
  private readonly _defaultTtlMs;
125
125
  private readonly _maxRequestsPerBin;
@@ -215,12 +215,12 @@ type CertificateFileOptions = CertificateOptions & {
215
215
  * Generate a self-signed certificate using only Node.js built-in crypto.
216
216
  * Returns PEM-encoded certificate and private key strings.
217
217
  */
218
- declare function generateCertificate(options?: CertificateOptions): CertificateResult;
218
+ export declare function generateCertificate(options?: CertificateOptions): CertificateResult;
219
219
  /**
220
220
  * Generate a self-signed certificate and write PEM files to disk.
221
221
  * Returns the same CertificateResult as generateCertificate().
222
222
  */
223
- declare function generateCertificateFiles(options: CertificateFileOptions): Promise<CertificateResult>;
223
+ export declare function generateCertificateFiles(options: CertificateFileOptions): Promise<CertificateResult>;
224
224
  //#endregion
225
225
  //#region src/tap-manager.d.ts
226
226
  /**
@@ -394,11 +394,22 @@ type MockHttpOptions = {
394
394
  */
395
395
  helmet?: boolean;
396
396
  /**
397
- * Whether to use Swagger for API documentation. Defaults to true.
397
+ * Whether to serve files from the package `public/` directory (favicon, logos).
398
+ * Defaults to true. Disable this when those files are served by another layer
399
+ * such as Cloudflare Workers Assets.
400
+ */
401
+ staticFiles?: boolean;
402
+ /**
403
+ * Whether to serve the Docula documentation site and OpenAPI spec. Defaults to true.
398
404
  */
399
405
  apiDocs?: boolean;
400
406
  /**
401
- * Whether to use Swagger UI. Defaults to true.
407
+ * Path to the built Docula site (`site/dist`). Defaults to the package's
408
+ * `site/dist` directory. Explicit paths are resolved from the current working directory.
409
+ */
410
+ siteDistPath?: string;
411
+ /**
412
+ * Configure which httpbin-style mock routes to enable. Defaults to all enabled.
402
413
  */
403
414
  httpBin?: HttpBinOptions;
404
415
  /**
@@ -414,6 +425,17 @@ type MockHttpOptions = {
414
425
  * Whether to enable logging. Defaults to true.
415
426
  */
416
427
  logging?: boolean;
428
+ /**
429
+ * Fastify plugin boot timeout in milliseconds. Set to `0` to disable the
430
+ * timeout (needed on Cloudflare Workers, where avvio timers are unreliable).
431
+ */
432
+ pluginTimeout?: number;
433
+ /**
434
+ * Whether to start the request-bin cleanup timer during `initialize()`.
435
+ * Defaults to true. Disable this on Cloudflare Workers, where `setInterval`
436
+ * during startup can hang the isolate.
437
+ */
438
+ startBins?: boolean;
417
439
  /**
418
440
  * HTTPS configuration. Set to true to auto-generate a self-signed certificate,
419
441
  * or provide an object with cert/key strings/paths or auto-generation options.
@@ -437,8 +459,12 @@ declare class MockHttp extends Hookified {
437
459
  private _host;
438
460
  private _autoDetectPort;
439
461
  private _helmet;
462
+ private _staticFiles;
440
463
  private _apiDocs;
464
+ private _siteDistPath;
441
465
  private _logging;
466
+ private _pluginTimeout?;
467
+ private _startBins;
442
468
  private _httpBin;
443
469
  private _rateLimit?;
444
470
  private _http2;
@@ -490,15 +516,35 @@ declare class MockHttp extends Hookified {
490
516
  */
491
517
  set helmet(helmet: boolean);
492
518
  /**
493
- * Whether to use Swagger for API documentation. Defaults to true.
519
+ * Whether to serve files from the package `public/` directory. Defaults to true.
520
+ * @default true
521
+ */
522
+ get staticFiles(): boolean;
523
+ /**
524
+ * Whether to serve files from the package `public/` directory. Defaults to true.
525
+ * @default true
526
+ */
527
+ set staticFiles(staticFiles: boolean);
528
+ /**
529
+ * Whether to serve the Docula documentation site and OpenAPI spec. Defaults to true.
494
530
  * @default true
495
531
  */
496
532
  get apiDocs(): boolean;
497
533
  /**
498
- * Whether to use Swagger for API documentation. Defaults to true.
534
+ * Whether to serve the Docula documentation site and OpenAPI spec. Defaults to true.
499
535
  * @default true
500
536
  */
501
537
  set apiDocs(apiDocs: boolean);
538
+ /**
539
+ * Path to the built Docula site served when `apiDocs` is enabled.
540
+ * @default the package `site/dist` directory
541
+ */
542
+ get siteDistPath(): string;
543
+ /**
544
+ * Path to the built Docula site served when `apiDocs` is enabled.
545
+ * @default the package `site/dist` directory
546
+ */
547
+ set siteDistPath(siteDistPath: string);
502
548
  /**
503
549
  * Whether to enable logging. Defaults to true.
504
550
  * @default true
@@ -509,6 +555,24 @@ declare class MockHttp extends Hookified {
509
555
  * @default true
510
556
  */
511
557
  set logging(logging: boolean);
558
+ /**
559
+ * Fastify plugin boot timeout in milliseconds. `undefined` uses Fastify's default.
560
+ */
561
+ get pluginTimeout(): number | undefined;
562
+ /**
563
+ * Fastify plugin boot timeout in milliseconds. `undefined` uses Fastify's default.
564
+ */
565
+ set pluginTimeout(pluginTimeout: number | undefined);
566
+ /**
567
+ * Whether to start the request-bin cleanup timer during `initialize()`.
568
+ * @default true
569
+ */
570
+ get startBins(): boolean;
571
+ /**
572
+ * Whether to start the request-bin cleanup timer during `initialize()`.
573
+ * @default true
574
+ */
575
+ set startBins(startBins: boolean);
512
576
  /**
513
577
  * HTTPS configuration. Set to true to auto-generate a self-signed certificate,
514
578
  * or provide an HttpsOptions object with cert/key or auto-generation options.
@@ -589,6 +653,11 @@ declare class MockHttp extends Hookified {
589
653
  * The BinManager instance for managing request bins.
590
654
  */
591
655
  set bins(bins: BinManager);
656
+ /**
657
+ * Register plugins and routes without listening. Use `inject()` against
658
+ * `server`, or call `start()` to bind a port.
659
+ */
660
+ initialize(): Promise<void>;
592
661
  /**
593
662
  * Start the Fastify server. If the server is already running, it will be closed and restarted.
594
663
  */
@@ -603,10 +672,20 @@ declare class MockHttp extends Hookified {
603
672
  */
604
673
  detectPort(): Promise<number>;
605
674
  /**
606
- * This will register the API documentation routes including openapi and swagger ui.
675
+ * Register OpenAPI generation and the Docula documentation site.
607
676
  * @param fastifyInstance - the server instance to register the routes on.
608
677
  */
609
678
  registerApiDocs(fastifyInstance?: FastifyInstance): Promise<void>;
679
+ /**
680
+ * Register `@fastify/swagger` and the live `/openapi.json` spec route.
681
+ * @param fastifyInstance - the server instance to register the routes on.
682
+ */
683
+ registerSwagger(fastifyInstance?: FastifyInstance): Promise<void>;
684
+ /**
685
+ * Serve the built Docula site from `siteDistPath` when the directory exists.
686
+ * @param fastifyInstance - the server instance to register the routes on.
687
+ */
688
+ registerSite(fastifyInstance?: FastifyInstance): Promise<void>;
610
689
  /**
611
690
  * Register the HTTP methods routes.
612
691
  * @param fastifyInstance - the server instance to register the routes on.
@@ -668,6 +747,6 @@ declare class MockHttp extends Hookified {
668
747
  }
669
748
  //#endregion
670
749
  //#region src/index.d.ts
671
- declare const start: () => Promise<MockHttp>;
750
+ export declare const start: () => Promise<MockHttp>;
672
751
  //#endregion
673
- export { type Bin, BinManager, type BinManagerOptions, type BinStore, type CapturedRequest, type CertificateFileOptions, type CertificateOptions, type CertificateResult, type HttpsOptions, InMemoryBinStore, type InjectionMatcher, type InjectionResponse, type InjectionTap, MockHttp as default, MockHttp as mockhttp, generateCertificate, generateCertificateFiles, start };
752
+ export { type Bin, type BinManagerOptions, type BinStore, type CapturedRequest, type CertificateFileOptions, type CertificateOptions, type CertificateResult, type HttpsOptions, type InjectionMatcher, type InjectionResponse, type InjectionTap, MockHttp as default, MockHttp as mockhttp };