mockaton 0.10.4 → 0.10.6

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "mockaton",
3
3
  "description": "A deterministic server-side for developing and testing frontend clients",
4
4
  "type": "module",
5
- "version": "0.10.4",
5
+ "version": "0.10.6",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
8
8
  "license": "MIT",
package/src/Dashboard.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Route } from '../Route.js'
2
- import { DP, DF } from '../ApiConstants.js'
2
+ import { API, DF } from '../ApiConstants.js'
3
3
 
4
4
 
5
5
  const Strings = {
@@ -42,9 +42,9 @@ const refPayloadFile = useRef()
42
42
 
43
43
  function init() {
44
44
  Promise.all([
45
- DP.mocks,
46
- DP.cookies,
47
- DP.comments
45
+ API.mocks,
46
+ API.cookies,
47
+ API.comments
48
48
  ].map(api => fetch(api).then(res => res.ok && res.json())))
49
49
  .then(App)
50
50
  .catch(console.error)
@@ -85,7 +85,7 @@ function ResetButton() {
85
85
  return (
86
86
  r('button', {
87
87
  onClick() {
88
- fetch(DP.reset, { method: 'PATCH' })
88
+ fetch(API.reset, { method: 'PATCH' })
89
89
  .then(init)
90
90
  .catch(console.error)
91
91
  }
@@ -101,7 +101,7 @@ function CookieSelector({ list }) {
101
101
  autocomplete: 'off',
102
102
  disabled: list.length <= 1,
103
103
  onChange() {
104
- fetch(DP.cookies, {
104
+ fetch(API.cookies, {
105
105
  method: 'PATCH',
106
106
  body: JSON.stringify({ [DF.currentCookieKey]: this.value })
107
107
  })
@@ -122,7 +122,7 @@ function BulkSelector({ comments }) {
122
122
  autocomplete: 'off',
123
123
  disabled: comments.length <= 1,
124
124
  onChange() {
125
- fetch(DP.bulkSelect, {
125
+ fetch(API.bulkSelect, {
126
126
  method: 'PATCH',
127
127
  body: JSON.stringify({ [DF.comment]: this.value })
128
128
  })
@@ -200,7 +200,7 @@ function MockSelector({ items, selected }) {
200
200
  this.style.fontWeight = this.value === this.options[0].value // default is selected
201
201
  ? 'normal'
202
202
  : 'bold'
203
- fetch(DP.edit, {
203
+ fetch(API.edit, {
204
204
  method: 'PATCH',
205
205
  body: JSON.stringify({ [DF.file]: this.value })
206
206
  }).then(() => {
@@ -227,7 +227,7 @@ function DelayToggler({ name, checked }) {
227
227
  name,
228
228
  checked,
229
229
  onChange(event) {
230
- fetch(DP.edit, {
230
+ fetch(API.edit, {
231
231
  method: 'PATCH',
232
232
  body: JSON.stringify({
233
233
  [DF.file]: this.name,
@@ -272,7 +272,7 @@ function TransformSelector({ items, selected }) {
272
272
  className: className(selected === items[0]),
273
273
  autocomplete: 'off',
274
274
  onChange() {
275
- fetch(DP.transform, {
275
+ fetch(API.transform, {
276
276
  method: 'PATCH',
277
277
  body: JSON.stringify({ [DF.file]: this.value })
278
278
  }).then(() => {
package/src/Mockaton.js CHANGED
@@ -30,7 +30,7 @@ export function Mockaton(options) {
30
30
  .listen(Config.port, Config.host, function (error) {
31
31
  const { address, port } = this.address()
32
32
  const url = `http://${address}:${port}`
33
- console.log('Listening on', url)
33
+ console.log('Listening', url)
34
34
  console.log('Dashboard', url + API.dashboard)
35
35
  if (error)
36
36
  console.error(error)
@@ -1,13 +1,12 @@
1
1
  import { join } from 'node:path'
2
- import { existsSync, lstatSync } from 'node:fs'
2
+ import { existsSync as exists, lstatSync as lstat } from 'node:fs'
3
3
 
4
4
  import { Config } from './Config.js'
5
5
  import { sendFile, sendPartialContent } from './utils/http-response.js'
6
6
 
7
7
 
8
8
  export function isStatic(req) {
9
- return Config.staticDir &&
10
- existsSync(resolvePath(req))
9
+ return Config.staticDir && exists(resolvePath(req))
11
10
  }
12
11
 
13
12
  export async function dispatchStatic(req, response) {
@@ -20,8 +19,8 @@ export async function dispatchStatic(req, response) {
20
19
 
21
20
  function resolvePath(req) {
22
21
  const candidate = join(Config.staticDir, req.url)
23
- if (existsSync(candidate))
24
- return lstatSync(candidate).isDirectory()
22
+ if (exists(candidate))
23
+ return lstat(candidate).isDirectory()
25
24
  ? candidate + '/index.html'
26
25
  : candidate
27
26
  }
@@ -1,5 +1,5 @@
1
1
  import { join } from 'node:path'
2
- import { readdirSync, lstatSync } from 'node:fs'
2
+ import { readdirSync as readDir, lstatSync } from 'node:fs'
3
3
 
4
4
  import { Route } from './Route.js'
5
5
  import { Config } from './Config.js'
@@ -23,7 +23,7 @@ export function init() {
23
23
  collection = {}
24
24
  cookie.init(Config.cookies)
25
25
 
26
- const files = readdirSync(Config.mocksDir, { recursive: true })
26
+ const files = readDir(Config.mocksDir, { recursive: true })
27
27
  .filter(f => Config.allowedExt.test(f) && lstatSync(join(Config.mocksDir, f)).isFile())
28
28
  .sort()
29
29