@jaredwray/mockhttp 1.1.0 → 1.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 +34 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +50 -33
- package/package.json +13 -20
package/README.md
CHANGED
|
@@ -21,6 +21,18 @@ A simple HTTP server that can be used to mock HTTP responses for testing purpose
|
|
|
21
21
|
* Auto detect the port that is not in use
|
|
22
22
|
* Maintained and updated regularly!
|
|
23
23
|
|
|
24
|
+
# Table of Contents
|
|
25
|
+
- [Deploy via Docker](#deploy-via-docker)
|
|
26
|
+
- [Deploy via Docker Compose](#deploy-via-docker-compose)
|
|
27
|
+
- [Deploy via NodeJS](#deploy-via-nodejs)
|
|
28
|
+
- [Response Injection (Tap Feature)](#response-injection-tap-feature)
|
|
29
|
+
- [Rate Limiting](#rate-limiting)
|
|
30
|
+
- [Logging](#logging)
|
|
31
|
+
- [API Reference](#api-reference)
|
|
32
|
+
- [About mockhttp.org](#about-mockhttporg)
|
|
33
|
+
- [Contributing](#contributing)
|
|
34
|
+
- [License](#license)
|
|
35
|
+
|
|
24
36
|
# Deploy via Docker
|
|
25
37
|
```bash
|
|
26
38
|
docker run -d -p 3000:3000 jaredwray/mockhttp
|
|
@@ -405,6 +417,26 @@ await mock.start(); // Restarts with new settings
|
|
|
405
417
|
|
|
406
418
|
For the complete list of options, see the [@fastify/rate-limit documentation](https://github.com/fastify/fastify-rate-limit#options).
|
|
407
419
|
|
|
420
|
+
# Logging
|
|
421
|
+
|
|
422
|
+
MockHttp uses [Pino](https://github.com/pinojs/pino) for logging via Fastify's built-in logger. Logging is **enabled by default** but can be disabled when needed.
|
|
423
|
+
|
|
424
|
+
## Disabling Logging
|
|
425
|
+
|
|
426
|
+
```javascript
|
|
427
|
+
import { MockHttp } from '@jaredwray/mockhttp';
|
|
428
|
+
|
|
429
|
+
const mock = new MockHttp({ logging: false });
|
|
430
|
+
await mock.start();
|
|
431
|
+
// Server runs silently without any log output
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
You can also disable logging via the `LOGGING` environment variable:
|
|
435
|
+
|
|
436
|
+
```bash
|
|
437
|
+
LOGGING=false node your-app.js
|
|
438
|
+
```
|
|
439
|
+
|
|
408
440
|
# API Reference
|
|
409
441
|
|
|
410
442
|
## MockHttp Class
|
|
@@ -423,6 +455,7 @@ new MockHttp(options?)
|
|
|
423
455
|
- `helmet?`: boolean - Use Helmet for security headers (default: true)
|
|
424
456
|
- `apiDocs?`: boolean - Enable Swagger API documentation (default: true)
|
|
425
457
|
- `rateLimit?`: RateLimitPluginOptions - Configure rate limiting (default: 1000 req/min, localhost excluded)
|
|
458
|
+
- `logging?`: boolean - Enable logging (default: true)
|
|
426
459
|
- `httpBin?`: HttpBinOptions - Configure which httpbin routes to enable
|
|
427
460
|
- `httpMethods?`: boolean - Enable HTTP method routes (default: true)
|
|
428
461
|
- `redirects?`: boolean - Enable redirect routes (default: true)
|
|
@@ -443,6 +476,7 @@ new MockHttp(options?)
|
|
|
443
476
|
- `autoDetectPort`: boolean - Get/set auto-detect port behavior
|
|
444
477
|
- `helmet`: boolean - Get/set Helmet security headers
|
|
445
478
|
- `apiDocs`: boolean - Get/set API documentation
|
|
479
|
+
- `logging`: boolean - Get/set logging enabled state
|
|
446
480
|
- `rateLimit`: RateLimitPluginOptions | undefined - Get/set rate limiting options
|
|
447
481
|
- `httpBin`: HttpBinOptions - Get/set httpbin route options
|
|
448
482
|
- `server`: FastifyInstance - Get/set the Fastify server instance
|
package/dist/index.d.ts
CHANGED
|
@@ -168,6 +168,10 @@ type MockHttpOptions = {
|
|
|
168
168
|
* Hookified options.
|
|
169
169
|
*/
|
|
170
170
|
hookOptions?: HookifiedOptions;
|
|
171
|
+
/**
|
|
172
|
+
* Whether to enable logging. Defaults to true.
|
|
173
|
+
*/
|
|
174
|
+
logging?: boolean;
|
|
171
175
|
};
|
|
172
176
|
declare class MockHttp extends Hookified {
|
|
173
177
|
private _port;
|
|
@@ -175,6 +179,7 @@ declare class MockHttp extends Hookified {
|
|
|
175
179
|
private _autoDetectPort;
|
|
176
180
|
private _helmet;
|
|
177
181
|
private _apiDocs;
|
|
182
|
+
private _logging;
|
|
178
183
|
private _httpBin;
|
|
179
184
|
private _rateLimit?;
|
|
180
185
|
private _server;
|
|
@@ -230,6 +235,16 @@ declare class MockHttp extends Hookified {
|
|
|
230
235
|
* @default true
|
|
231
236
|
*/
|
|
232
237
|
set apiDocs(apiDocs: boolean);
|
|
238
|
+
/**
|
|
239
|
+
* Whether to enable logging. Defaults to true.
|
|
240
|
+
* @default true
|
|
241
|
+
*/
|
|
242
|
+
get logging(): boolean;
|
|
243
|
+
/**
|
|
244
|
+
* Whether to enable logging. Defaults to true.
|
|
245
|
+
* @default true
|
|
246
|
+
*/
|
|
247
|
+
set logging(logging: boolean);
|
|
233
248
|
/**
|
|
234
249
|
* HTTP Bin options. Defaults to all enabled.
|
|
235
250
|
*/
|
package/dist/index.js
CHANGED
|
@@ -16,19 +16,22 @@ import Fastify from "fastify";
|
|
|
16
16
|
import { Hookified } from "hookified";
|
|
17
17
|
|
|
18
18
|
// src/fastify-config.ts
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
function getFastifyConfig(logging = true) {
|
|
20
|
+
return {
|
|
21
|
+
logger: logging ? {
|
|
22
|
+
transport: {
|
|
23
|
+
target: "pino-pretty",
|
|
24
|
+
options: {
|
|
25
|
+
colorize: true,
|
|
26
|
+
translateTime: true,
|
|
27
|
+
ignore: "pid,hostname",
|
|
28
|
+
singleLine: true
|
|
29
|
+
}
|
|
28
30
|
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
31
|
+
} : false
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
__name(getFastifyConfig, "getFastifyConfig");
|
|
32
35
|
|
|
33
36
|
// src/routes/anything/index.ts
|
|
34
37
|
var anythingSchema = {
|
|
@@ -2713,7 +2716,7 @@ import { fastifySwaggerUi } from "@fastify/swagger-ui";
|
|
|
2713
2716
|
// package.json
|
|
2714
2717
|
var package_default = {
|
|
2715
2718
|
name: "@jaredwray/mockhttp",
|
|
2716
|
-
version: "1.
|
|
2719
|
+
version: "1.2.0",
|
|
2717
2720
|
description: "Mock Http - Easy way to mock http with httpbin replacement",
|
|
2718
2721
|
type: "module",
|
|
2719
2722
|
main: "dist/index.js",
|
|
@@ -2764,43 +2767,36 @@ var package_default = {
|
|
|
2764
2767
|
},
|
|
2765
2768
|
homepage: "https://github.com/jaredwray/mockhttp#readme",
|
|
2766
2769
|
devDependencies: {
|
|
2767
|
-
"@biomejs/biome": "^2.3.
|
|
2768
|
-
"@swc/core": "^1.15.
|
|
2770
|
+
"@biomejs/biome": "^2.3.8",
|
|
2771
|
+
"@swc/core": "^1.15.3",
|
|
2769
2772
|
"@types/html-escaper": "^3.0.4",
|
|
2770
|
-
"@vitest/coverage-v8": "^4.0.
|
|
2771
|
-
rimraf: "^6.1.
|
|
2772
|
-
tsup: "^8.5.
|
|
2773
|
-
tsx: "^4.
|
|
2773
|
+
"@vitest/coverage-v8": "^4.0.15",
|
|
2774
|
+
rimraf: "^6.1.2",
|
|
2775
|
+
tsup: "^8.5.1",
|
|
2776
|
+
tsx: "^4.21.0",
|
|
2774
2777
|
typescript: "^5.9.3",
|
|
2775
|
-
vitest: "^4.0.
|
|
2778
|
+
vitest: "^4.0.15"
|
|
2776
2779
|
},
|
|
2777
2780
|
dependencies: {
|
|
2778
2781
|
"@fastify/cookie": "^11.0.2",
|
|
2779
2782
|
"@fastify/helmet": "^13.0.2",
|
|
2780
2783
|
"@fastify/rate-limit": "^10.3.0",
|
|
2781
2784
|
"@fastify/static": "^8.3.0",
|
|
2782
|
-
"@fastify/swagger": "^9.6.
|
|
2785
|
+
"@fastify/swagger": "^9.6.1",
|
|
2783
2786
|
"@fastify/swagger-ui": "^5.2.3",
|
|
2784
|
-
"@scalar/api-reference": "^1.
|
|
2787
|
+
"@scalar/api-reference": "^1.40.4",
|
|
2785
2788
|
"detect-port": "^2.1.0",
|
|
2786
2789
|
fastify: "^5.6.2",
|
|
2787
|
-
hookified: "^1.
|
|
2790
|
+
hookified: "^1.14.0",
|
|
2788
2791
|
"html-escaper": "^3.0.3",
|
|
2789
2792
|
pino: "^10.1.0",
|
|
2790
|
-
"pino-pretty": "^13.1.
|
|
2793
|
+
"pino-pretty": "^13.1.3"
|
|
2791
2794
|
},
|
|
2792
2795
|
files: [
|
|
2793
2796
|
"dist",
|
|
2794
2797
|
"public",
|
|
2795
2798
|
"LICENCE"
|
|
2796
|
-
]
|
|
2797
|
-
pnpm: {
|
|
2798
|
-
onlyBuiltDependencies: [
|
|
2799
|
-
"@swc/core",
|
|
2800
|
-
"unrs-resolver",
|
|
2801
|
-
"vue-demi"
|
|
2802
|
-
]
|
|
2803
|
-
}
|
|
2799
|
+
]
|
|
2804
2800
|
};
|
|
2805
2801
|
|
|
2806
2802
|
// src/swagger.ts
|
|
@@ -2985,6 +2981,7 @@ var MockHttp = class extends Hookified {
|
|
|
2985
2981
|
_autoDetectPort = true;
|
|
2986
2982
|
_helmet = true;
|
|
2987
2983
|
_apiDocs = true;
|
|
2984
|
+
_logging = true;
|
|
2988
2985
|
_httpBin = {
|
|
2989
2986
|
httpMethods: true,
|
|
2990
2987
|
redirects: true,
|
|
@@ -3031,6 +3028,9 @@ var MockHttp = class extends Hookified {
|
|
|
3031
3028
|
this._rateLimit = options.rateLimit;
|
|
3032
3029
|
}
|
|
3033
3030
|
}
|
|
3031
|
+
if (options?.logging !== void 0) {
|
|
3032
|
+
this._logging = options.logging;
|
|
3033
|
+
}
|
|
3034
3034
|
}
|
|
3035
3035
|
/**
|
|
3036
3036
|
* The port to listen on. If not provided, defaults to 3000 and detects the next available port if in use.
|
|
@@ -3103,6 +3103,20 @@ var MockHttp = class extends Hookified {
|
|
|
3103
3103
|
this._apiDocs = apiDocs;
|
|
3104
3104
|
}
|
|
3105
3105
|
/**
|
|
3106
|
+
* Whether to enable logging. Defaults to true.
|
|
3107
|
+
* @default true
|
|
3108
|
+
*/
|
|
3109
|
+
get logging() {
|
|
3110
|
+
return this._logging;
|
|
3111
|
+
}
|
|
3112
|
+
/**
|
|
3113
|
+
* Whether to enable logging. Defaults to true.
|
|
3114
|
+
* @default true
|
|
3115
|
+
*/
|
|
3116
|
+
set logging(logging) {
|
|
3117
|
+
this._logging = logging;
|
|
3118
|
+
}
|
|
3119
|
+
/**
|
|
3106
3120
|
* HTTP Bin options. Defaults to all enabled.
|
|
3107
3121
|
*/
|
|
3108
3122
|
get httpBin() {
|
|
@@ -3164,7 +3178,7 @@ var MockHttp = class extends Hookified {
|
|
|
3164
3178
|
if (this._server) {
|
|
3165
3179
|
await this._server.close();
|
|
3166
3180
|
}
|
|
3167
|
-
this._server = Fastify(
|
|
3181
|
+
this._server = Fastify(getFastifyConfig(this._logging));
|
|
3168
3182
|
this._server.addHook("onRequest", async (request, reply) => {
|
|
3169
3183
|
const matchedTap = this._taps.matchRequest(request);
|
|
3170
3184
|
if (matchedTap) {
|
|
@@ -3406,6 +3420,9 @@ var start = /* @__PURE__ */ __name(async () => {
|
|
|
3406
3420
|
if (process2.env.HOST) {
|
|
3407
3421
|
mockHttp.host = process2.env.HOST;
|
|
3408
3422
|
}
|
|
3423
|
+
if (process2.env.LOGGING === "false") {
|
|
3424
|
+
mockHttp.logging = false;
|
|
3425
|
+
}
|
|
3409
3426
|
await mockHttp.start();
|
|
3410
3427
|
return mockHttp;
|
|
3411
3428
|
}, "start");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jaredwray/mockhttp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Mock Http - Easy way to mock http with httpbin replacement",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -51,41 +51,34 @@
|
|
|
51
51
|
},
|
|
52
52
|
"homepage": "https://github.com/jaredwray/mockhttp#readme",
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@biomejs/biome": "^2.3.
|
|
55
|
-
"@swc/core": "^1.15.
|
|
54
|
+
"@biomejs/biome": "^2.3.8",
|
|
55
|
+
"@swc/core": "^1.15.3",
|
|
56
56
|
"@types/html-escaper": "^3.0.4",
|
|
57
|
-
"@vitest/coverage-v8": "^4.0.
|
|
58
|
-
"rimraf": "^6.1.
|
|
59
|
-
"tsup": "^8.5.
|
|
60
|
-
"tsx": "^4.
|
|
57
|
+
"@vitest/coverage-v8": "^4.0.15",
|
|
58
|
+
"rimraf": "^6.1.2",
|
|
59
|
+
"tsup": "^8.5.1",
|
|
60
|
+
"tsx": "^4.21.0",
|
|
61
61
|
"typescript": "^5.9.3",
|
|
62
|
-
"vitest": "^4.0.
|
|
62
|
+
"vitest": "^4.0.15"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@fastify/cookie": "^11.0.2",
|
|
66
66
|
"@fastify/helmet": "^13.0.2",
|
|
67
67
|
"@fastify/rate-limit": "^10.3.0",
|
|
68
68
|
"@fastify/static": "^8.3.0",
|
|
69
|
-
"@fastify/swagger": "^9.6.
|
|
69
|
+
"@fastify/swagger": "^9.6.1",
|
|
70
70
|
"@fastify/swagger-ui": "^5.2.3",
|
|
71
|
-
"@scalar/api-reference": "^1.
|
|
71
|
+
"@scalar/api-reference": "^1.40.4",
|
|
72
72
|
"detect-port": "^2.1.0",
|
|
73
73
|
"fastify": "^5.6.2",
|
|
74
|
-
"hookified": "^1.
|
|
74
|
+
"hookified": "^1.14.0",
|
|
75
75
|
"html-escaper": "^3.0.3",
|
|
76
76
|
"pino": "^10.1.0",
|
|
77
|
-
"pino-pretty": "^13.1.
|
|
77
|
+
"pino-pretty": "^13.1.3"
|
|
78
78
|
},
|
|
79
79
|
"files": [
|
|
80
80
|
"dist",
|
|
81
81
|
"public",
|
|
82
82
|
"LICENCE"
|
|
83
|
-
]
|
|
84
|
-
"pnpm": {
|
|
85
|
-
"onlyBuiltDependencies": [
|
|
86
|
-
"@swc/core",
|
|
87
|
-
"unrs-resolver",
|
|
88
|
-
"vue-demi"
|
|
89
|
-
]
|
|
90
|
-
}
|
|
83
|
+
]
|
|
91
84
|
}
|