mockaton 11.1.3 → 11.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/Makefile CHANGED
@@ -1,10 +1,15 @@
1
- docker: docker-build docker-start
1
+ docker: docker-build docker-run
2
2
 
3
3
  docker-build:
4
- docker build -t mockaton .
4
+ @docker build --no-cache --tag mockaton $(PWD)
5
5
 
6
- docker-start: docker-stop
7
- docker run --name mockaton -p 127.0.0.1:2020:2020 mockaton
6
+ docker-run: docker-stop
7
+ @docker run --name mockaton \
8
+ --publish 127.0.0.1:2020:2020 \
9
+ --volume $(PWD)/mockaton.config.js:/app/mockaton.config.js \
10
+ --volume $(PWD)/mockaton-mocks:/app/mockaton-mocks \
11
+ --volume $(PWD)/mockaton-static-mocks:/app/mockaton-static-mocks \
12
+ mockaton
8
13
 
9
14
  docker-stop:
10
15
  @docker stop mockaton >/dev/null 2>&1 || true
@@ -23,7 +28,7 @@ test:
23
28
 
24
29
  test-docker:
25
30
  @docker run --rm --interactive --tty \
26
- --volume .:/app \
31
+ --volume $(PWD):/app \
27
32
  --workdir /app \
28
33
  node:24 \
29
34
  make test
@@ -39,8 +44,10 @@ pixaton:
39
44
  --import=./pixaton-tests/_setup.js \
40
45
  'pixaton-tests/**/*.test.js'
41
46
 
47
+
42
48
  outdated:
43
49
  @npm outdated --parseable |\
44
50
  awk -F: '{ printf "npm i %-30s ;# %s\n", $$4, $$2 }'
45
51
 
52
+
46
53
  .PHONY: *
package/README.md CHANGED
@@ -14,12 +14,35 @@ With Mockaton, you don’t need to write code for wiring up your
14
14
  mocks. Instead, a given directory is scanned for filenames
15
15
  following a convention similar to the URLs.
16
16
 
17
- For example, for [/api/user/123](#), the filename could be:
17
+ For example, for [/api/company/123](#), the filename could be:
18
18
 
19
19
  <pre>
20
- <code>my-mocks-dir/<b>api/user</b>/[user-id].GET.200.json</code>
20
+ <code>my-mocks-dir/<b>api/company</b>/[company-id].GET.200.json</code>
21
21
  </pre>
22
22
 
23
+ <br/>
24
+
25
+
26
+ ## Quick Start (Docker)
27
+ This will spin up Mockaton with the mock directories included in this repo:
28
+ [mockaton-mocks/](./mockaton-mocks) and [mockaton-static-mocks/](./mockaton-static-mocks)
29
+ mounted on the container.
30
+
31
+ ```sh
32
+ git clone https://github.com/ericfortis/mockaton.git --depth 1
33
+ cd mockaton
34
+ make docker
35
+ ```
36
+ Dashboard: http://localhost:2020/mockaton
37
+
38
+
39
+ Test it:
40
+ ```shell
41
+ curl localhost:2020/api/user
42
+ ```
43
+
44
+
45
+ <br/>
23
46
 
24
47
  ## Dashboard
25
48
 
@@ -125,7 +148,6 @@ If you commit the mocks to your repo, you don’t have to downgrade backends whe
125
148
 
126
149
  <img src="./demo-app-vite/pixaton-tests/pic-for-readme.vp740x880.light.gold.png" alt="Mockaton Demo App Screenshot" width="740" />
127
150
 
128
- <br/>
129
151
 
130
152
  ### Standalone demo server (Docker)
131
153
  You can demo your app by compiling the frontend and putting
@@ -150,22 +172,6 @@ make start-standalone-demo
150
172
 
151
173
  <br/>
152
174
 
153
- ## Quick Start (Docker)
154
- This will spin up Mockaton with the mocks included in this repo:
155
- [mockaton-mocks/](./mockaton-mocks) and [mockaton-static-mocks/](./mockaton-static-mocks)
156
-
157
- ```sh
158
- git clone https://github.com/ericfortis/mockaton.git --depth 1
159
- make docker
160
- ```
161
- Dashboard: http://localhost:2020/mockaton
162
-
163
-
164
- Test it:
165
- ```shell
166
- curl localhost:2020/api/user
167
- ```
168
-
169
175
 
170
176
  ## Usage Without Docker
171
177
 
@@ -227,8 +233,6 @@ Mockaton looks for a file `mockaton.config.js` in its current working directory.
227
233
  <details>
228
234
  <summary>Defaults Overview… </summary>
229
235
 
230
- As an overview, these are the defaults:
231
-
232
236
  ```js
233
237
  import {
234
238
  defineConfig,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "mockaton",
3
3
  "description": "HTTP Mock Server",
4
4
  "type": "module",
5
- "version": "11.1.3",
5
+ "version": "11.2.0",
6
6
  "types": "./index.d.ts",
7
7
  "exports": {
8
8
  ".": {
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "devDependencies": {
29
29
  "pixaton": "1.1.3",
30
- "puppeteer": "24.24.1"
30
+ "puppeteer": "24.29.1"
31
31
  },
32
32
  "engines": {
33
33
  "node": ">=22.18 <23 || >=23.6"
package/src/Dashboard.css CHANGED
@@ -235,6 +235,9 @@ header {
235
235
  margin: 0;
236
236
  margin-right: 4px;
237
237
  }
238
+ input:enabled + span {
239
+ cursor: pointer;
240
+ }
238
241
  input:disabled + span {
239
242
  opacity: 0.8;
240
243
  }
@@ -287,23 +290,30 @@ header {
287
290
  top: 62px;
288
291
  right: 10px;
289
292
  left: auto;
290
- padding: 20px;
291
293
  border: 1px solid var(--colorSecondaryActionBorder);
292
- text-align: left;
293
294
  color: var(--colorText);
294
295
  border-radius: var(--radius);
295
296
  box-shadow: var(--boxShadow1);
296
297
  background: var(--colorHeaderBackground);
297
298
 
298
- a {
299
- color: var(--colorAccent);
300
- }
299
+ > div {
300
+ display: inline-flex;
301
+ flex-direction: column;
302
+ padding: 20px;
303
+ cursor: auto;
304
+ gap: 12px;
305
+ text-align: left;
301
306
 
302
- .GroupByMethod {
303
- display: flex;
304
- align-items: center;
305
- margin-bottom: 12px;
306
- gap: 6px;
307
+ a {
308
+ color: var(--colorAccent);
309
+ }
310
+
311
+ .GroupByMethod {
312
+ display: flex;
313
+ align-items: center;
314
+ gap: 6px;
315
+ cursor: pointer;
316
+ }
307
317
  }
308
318
  }
309
319
 
@@ -610,10 +620,7 @@ table {
610
620
  > code {
611
621
  white-space: pre;
612
622
  tab-size: 2;
613
-
614
- > .json {
615
- color: var(--colorSecondaryAction);
616
- }
623
+ color: var(--colorSecondaryAction);
617
624
 
618
625
  .syntaxPunc {
619
626
  color: var(--colorSecondaryAction);
package/src/Dashboard.js CHANGED
@@ -36,7 +36,6 @@ const CSS = {
36
36
  rightSide: null,
37
37
  status4xx: null,
38
38
 
39
- json: null,
40
39
  syntaxAttr: null,
41
40
  syntaxAttrVal: null,
42
41
  syntaxKey: null,
@@ -251,20 +250,24 @@ function SettingsMenu(id) {
251
250
  }
252
251
  },
253
252
 
254
- r('label', className(CSS.GroupByMethod),
255
- r('input', {
256
- ref: firstInputRef,
257
- type: 'checkbox',
258
- checked: store.groupByMethod,
259
- onChange: store.toggleGroupByMethod
260
- }),
261
- r('span', null, t`Group by Method`)),
253
+ r('div', null,
254
+ r('label', className(CSS.GroupByMethod),
255
+ r('input', {
256
+ ref: firstInputRef,
257
+ type: 'checkbox',
258
+ checked: store.groupByMethod,
259
+ onChange: store.toggleGroupByMethod
260
+ }),
261
+ r('span', null, t`Group by Method`)),
262
+
263
+ r('a', {
264
+ href: 'https://github.com/ericfortis/mockaton',
265
+ target: '_blank',
266
+ rel: 'noopener noreferrer'
267
+ }, t`Documentation`),
262
268
 
263
- r('a', {
264
- href: 'https://github.com/ericfortis/mockaton',
265
- target: '_blank',
266
- rel: 'noopener noreferrer'
267
- }, t`Documentation`)))
269
+ r('p', null, `v${store.mockatonVersion}`)
270
+ )))
268
271
  }
269
272
 
270
273
 
@@ -650,7 +653,7 @@ async function updatePayloadViewer(proxied, file, response) {
650
653
  else {
651
654
  const body = await response.text() || t`/* Empty Response Body */`
652
655
  if (mime === 'application/json')
653
- payloadViewerCodeRef.elem.replaceChildren(r('span', className(CSS.json), SyntaxJSON(body)))
656
+ payloadViewerCodeRef.elem.replaceChildren(SyntaxJSON(body))
654
657
  else if (isXML(mime))
655
658
  payloadViewerCodeRef.elem.replaceChildren(SyntaxXML(body))
656
659
  else
@@ -755,9 +758,11 @@ function initRealTimeUpdates() {
755
758
  ErrorToast.close()
756
759
 
757
760
  const version = await response.json()
761
+ const shouldSkip = oldVersion === undefined
758
762
  if (oldVersion !== version) { // because it could be < or >
759
763
  oldVersion = version
760
- store.fetchState()
764
+ if (!shouldSkip)
765
+ store.fetchState()
761
766
  }
762
767
  longPoll()
763
768
  }
@@ -26,10 +26,13 @@ export const store = {
26
26
 
27
27
  getSyncVersion: api.getSyncVersion,
28
28
 
29
+ mockatonVersion: '',
30
+
29
31
  async fetchState() {
30
32
  try {
31
33
  const response = await api.getState()
32
34
  if (!response.ok) throw response
35
+ store.mockatonVersion = response.headers.get('server').split(' ').pop()
33
36
  Object.assign(store, await response.json())
34
37
  store.render()
35
38
  }
@@ -31,9 +31,6 @@ export async function dispatchMock(req, response) {
31
31
  if (cookie.getCurrent())
32
32
  response.setHeader('Set-Cookie', cookie.getCurrent())
33
33
 
34
- for (let i = 0; i < config.extraHeaders.length; i += 2) // TESTME
35
- response.setHeader(config.extraHeaders[i], config.extraHeaders[i + 1])
36
-
37
34
  response.statusCode = broker.auto500 ? 500 : broker.status // TESTME plugins can change it
38
35
  const { mime, body } = broker.auto500
39
36
  ? { mime: '', body: '' }
package/src/Mockaton.js CHANGED
@@ -41,7 +41,9 @@ export function Mockaton(options) {
41
41
 
42
42
  async function onRequest(req, response) {
43
43
  response.on('error', logger.warn)
44
- response.setHeader('Server', 'Mockaton')
44
+
45
+ for (let i = 0; i < config.extraHeaders.length; i += 2)
46
+ response.setHeader(config.extraHeaders[i], config.extraHeaders[i + 1])
45
47
 
46
48
  const url = req.url || ''
47
49
 
package/src/config.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { resolve } from 'node:path'
2
+ import pkgJSON from '../package.json' with { type: 'json' }
2
3
 
3
4
  import { logger } from './utils/logger.js'
4
5
  import { isDirectory } from './utils/fs.js'
@@ -81,6 +82,7 @@ export function setup(options) {
81
82
  Object.assign(config, options)
82
83
  validate(config, ConfigValidator)
83
84
  logger.setLevel(config.logLevel)
85
+ config.extraHeaders.push('Server', `Mockaton ${pkgJSON.version}`)
84
86
  }
85
87
 
86
88