mockaton 8.9.0 → 8.9.1
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 +1 -1
- package/package.json +1 -1
- package/src/Api.js +7 -0
- package/src/ApiConstants.js +2 -1
- package/src/Commander.js +5 -2
- package/src/Dashboard.js +1 -1
- package/src/ProxyRelay.js +3 -3
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ which is handy for setting up tests (see **Commander API** below).
|
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
|
|
33
|
-
##
|
|
33
|
+
## Fallback to your Backend
|
|
34
34
|
Mockaton can fallback to your real backend on routes you don’t have mocks
|
|
35
35
|
for. For that, type your backend address in the **Fallback Backend** field.
|
|
36
36
|
|
package/package.json
CHANGED
package/src/Api.js
CHANGED
|
@@ -78,6 +78,13 @@ function listStaticFiles(req, response) {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
function longPollAR_Events(req, response) {
|
|
81
|
+
// e.g. tab was hidden while new mocks were added or removed
|
|
82
|
+
const clientIsOutOfSync = parseInt(req.headers[DF.lastReceived_nAR], 10) !== countAR_Events()
|
|
83
|
+
if (clientIsOutOfSync) {
|
|
84
|
+
sendJSON(response, countAR_Events())
|
|
85
|
+
return
|
|
86
|
+
}
|
|
87
|
+
|
|
81
88
|
function onAddOrRemoveMock() {
|
|
82
89
|
unsubscribeAR_EventListener(onAddOrRemoveMock)
|
|
83
90
|
sendJSON(response, countAR_Events())
|
package/src/ApiConstants.js
CHANGED
|
@@ -20,7 +20,8 @@ export const DF = { // Dashboard Fields (XHR)
|
|
|
20
20
|
routeMethod: 'route_method',
|
|
21
21
|
routeUrlMask: 'route_url_mask',
|
|
22
22
|
delayed: 'delayed',
|
|
23
|
-
proxied: 'proxied'
|
|
23
|
+
proxied: 'proxied',
|
|
24
|
+
lastReceived_nAR: 'last_received_n_ar'
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
export const DEFAULT_500_COMMENT = '(Mockaton 500)'
|
package/src/Commander.js
CHANGED
|
@@ -85,9 +85,12 @@ export class Commander {
|
|
|
85
85
|
return this.#patch(API.reset)
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
getAR_EventsCount() {
|
|
88
|
+
getAR_EventsCount(nAR_EventReceived) {
|
|
89
89
|
return fetch(API.arEvents, {
|
|
90
|
-
signal: AbortSignal.timeout(LONG_POLL_SERVER_TIMEOUT + 1000)
|
|
90
|
+
signal: AbortSignal.timeout(LONG_POLL_SERVER_TIMEOUT + 1000),
|
|
91
|
+
headers: {
|
|
92
|
+
[DF.lastReceived_nAR]: nAR_EventReceived
|
|
93
|
+
}
|
|
91
94
|
})
|
|
92
95
|
}
|
|
93
96
|
}
|
package/src/Dashboard.js
CHANGED
|
@@ -512,7 +512,7 @@ async function pollAR_Events() {
|
|
|
512
512
|
return
|
|
513
513
|
try {
|
|
514
514
|
pollAR_Events.isPolling = true
|
|
515
|
-
const response = await mockaton.getAR_EventsCount()
|
|
515
|
+
const response = await mockaton.getAR_EventsCount(pollAR_Events.oldAR_EventsCount)
|
|
516
516
|
if (response.ok) {
|
|
517
517
|
const nAR_Events = await response.json()
|
|
518
518
|
if (pollAR_Events.oldAR_EventsCount !== nAR_Events) { // because it could be < or >
|
package/src/ProxyRelay.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { join } from 'node:path'
|
|
2
|
-
import { existsSync } from 'node:fs'
|
|
3
2
|
import { randomUUID } from 'node:crypto'
|
|
4
|
-
|
|
3
|
+
|
|
5
4
|
import { config } from './config.js'
|
|
6
5
|
import { extFor } from './utils/mime.js'
|
|
7
6
|
import { readBody } from './utils/http-request.js'
|
|
7
|
+
import { write, isFile } from './utils/fs.js'
|
|
8
8
|
import { makeMockFilename } from './Filename.js'
|
|
9
9
|
|
|
10
10
|
|
|
@@ -26,7 +26,7 @@ export async function proxy(req, response) {
|
|
|
26
26
|
if (config.collectProxied) {
|
|
27
27
|
const ext = extFor(proxyResponse.headers.get('content-type'))
|
|
28
28
|
let filename = makeMockFilename(req.url, req.method, proxyResponse.status, ext)
|
|
29
|
-
if (
|
|
29
|
+
if (isFile(join(config.mocksDir, filename))) // TESTME
|
|
30
30
|
filename = makeMockFilename(req.url + `(${randomUUID()})`, req.method, proxyResponse.status, ext)
|
|
31
31
|
write(join(config.mocksDir, filename), body)
|
|
32
32
|
}
|