mockaton 8.1.7 → 8.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-dashboard-dark.png +0 -0
- package/README-dashboard-light.png +0 -0
- package/package.json +1 -1
- package/src/Api.js +10 -3
- package/src/Commander.js +3 -0
- package/src/Dashboard.css +18 -9
- package/src/Dashboard.js +28 -1
- package/src/utils/http-response.js +6 -0
- package/ui-tests/bulk-select.vp1024x800.dark.gold.png +0 -0
- package/ui-tests/bulk-select.vp1024x800.light.gold.png +0 -0
- package/ui-tests/initial-dashboard-state.vp1024x800.dark.gold.png +0 -0
- package/ui-tests/initial-dashboard-state.vp1024x800.light.gold.png +0 -0
- package/ui-tests/payload-viewer-formats-json.vp1024x800.dark.gold.png +0 -0
- package/ui-tests/payload-viewer-formats-json.vp1024x800.light.gold.png +0 -0
- package/ui-tests/payload-viewer-renders-images.vp1024x800.dark.gold.png +0 -0
- package/ui-tests/payload-viewer-renders-images.vp1024x800.light.gold.png +0 -0
- package/ui-tests/select-mock-variant.vp1024x800.dark.gold.png +0 -0
- package/ui-tests/select-mock-variant.vp1024x800.light.gold.png +0 -0
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
package/src/Api.js
CHANGED
|
@@ -10,7 +10,7 @@ import { DF, API } from './ApiConstants.js'
|
|
|
10
10
|
import { parseJSON } from './utils/http-request.js'
|
|
11
11
|
import { listFilesRecursively } from './utils/fs.js'
|
|
12
12
|
import * as mockBrokersCollection from './mockBrokersCollection.js'
|
|
13
|
-
import { sendOK, sendBadRequest, sendJSON, sendFile } from './utils/http-response.js'
|
|
13
|
+
import { sendOK, sendBadRequest, sendJSON, sendFile, sendUnprocessableContent } from './utils/http-response.js'
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
export const apiGetRequests = new Map([
|
|
@@ -24,6 +24,7 @@ export const apiGetRequests = new Map([
|
|
|
24
24
|
[API.mocks, listMockBrokers],
|
|
25
25
|
[API.cookies, listCookies],
|
|
26
26
|
[API.comments, listComments],
|
|
27
|
+
[API.fallback, getProxyFallback],
|
|
27
28
|
[API.cors, getIsCorsAllowed],
|
|
28
29
|
[API.static, listStaticFiles]
|
|
29
30
|
])
|
|
@@ -44,6 +45,7 @@ function serveDashboardAsset(req, response) { sendFile(response, join(import.met
|
|
|
44
45
|
function listCookies(_, response) { sendJSON(response, cookie.list()) }
|
|
45
46
|
function listComments(_, response) { sendJSON(response, mockBrokersCollection.extractAllComments()) }
|
|
46
47
|
function listMockBrokers(_, response) { sendJSON(response, mockBrokersCollection.getAll()) }
|
|
48
|
+
function getProxyFallback(_, response) { sendJSON(response, Config.proxyFallback) }
|
|
47
49
|
function getIsCorsAllowed(_, response) { sendJSON(response, Config.corsAllowed) }
|
|
48
50
|
|
|
49
51
|
|
|
@@ -101,8 +103,13 @@ async function setRouteIsDelayed(req, response) {
|
|
|
101
103
|
|
|
102
104
|
async function updateProxyFallback(req, response) {
|
|
103
105
|
try {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
+
const fallback = await parseJSON(req)
|
|
107
|
+
if (fallback && !URL.canParse(fallback)) // TESTME
|
|
108
|
+
sendUnprocessableContent(response)
|
|
109
|
+
else {
|
|
110
|
+
Config.proxyFallback = fallback
|
|
111
|
+
sendOK(response)
|
|
112
|
+
}
|
|
106
113
|
}
|
|
107
114
|
catch (error) {
|
|
108
115
|
sendBadRequest(response, error)
|
package/src/Commander.js
CHANGED
package/src/Dashboard.css
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
--colorAccent: #0072d6;
|
|
9
9
|
--colorAccentAlt: #0e906c;
|
|
10
10
|
--colorBackground: #fff;
|
|
11
|
-
--colorHeaderBackground: #
|
|
11
|
+
--colorHeaderBackground: #f7f7f7;
|
|
12
12
|
--colorComboBoxBackground: #fafafa;
|
|
13
13
|
--colorComboBoxHeaderBackground: #fff;
|
|
14
14
|
--colorDisabled: #444;
|
|
@@ -61,7 +61,6 @@ select {
|
|
|
61
61
|
background: var(--colorComboBoxBackground);
|
|
62
62
|
color: var(--colorText);
|
|
63
63
|
cursor: pointer;
|
|
64
|
-
border-radius: 4px;
|
|
65
64
|
outline: 0;
|
|
66
65
|
|
|
67
66
|
&:enabled {
|
|
@@ -84,15 +83,16 @@ menu {
|
|
|
84
83
|
display: flex;
|
|
85
84
|
width: 100%;
|
|
86
85
|
align-items: flex-end;
|
|
87
|
-
padding:
|
|
86
|
+
padding: 12px 16px;
|
|
88
87
|
border-bottom: 1px solid rgba(127, 127, 127, 0.1);
|
|
89
88
|
background: var(--colorHeaderBackground);
|
|
90
|
-
|
|
89
|
+
box-shadow: var(--boxShadow1);
|
|
90
|
+
gap: 12px;
|
|
91
91
|
|
|
92
92
|
img {
|
|
93
93
|
width: 130px;
|
|
94
94
|
align-self: center;
|
|
95
|
-
margin-right:
|
|
95
|
+
margin-right: 18px;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
label {
|
|
@@ -102,14 +102,23 @@ menu {
|
|
|
102
102
|
font-size: 11px;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
input[type=url],
|
|
105
106
|
select {
|
|
107
|
+
height: 24px;
|
|
106
108
|
width: 150px;
|
|
107
|
-
padding: 4px;
|
|
109
|
+
padding: 4px 2px;
|
|
108
110
|
border-right: 3px solid transparent;
|
|
109
111
|
margin-top: 2px;
|
|
110
112
|
font-size: 11px;
|
|
111
113
|
background: var(--colorComboBoxHeaderBackground);
|
|
112
114
|
}
|
|
115
|
+
|
|
116
|
+
input[type=url] {
|
|
117
|
+
outline: 0;
|
|
118
|
+
padding: 0 6px;
|
|
119
|
+
box-shadow: var(--boxShadow1);
|
|
120
|
+
color: var(--colorText);
|
|
121
|
+
}
|
|
113
122
|
}
|
|
114
123
|
|
|
115
124
|
button {
|
|
@@ -139,7 +148,7 @@ menu {
|
|
|
139
148
|
main {
|
|
140
149
|
display: flex;
|
|
141
150
|
align-items: flex-start;
|
|
142
|
-
margin-top:
|
|
151
|
+
margin-top: 48px;
|
|
143
152
|
|
|
144
153
|
> table {
|
|
145
154
|
border-collapse: collapse;
|
|
@@ -159,7 +168,7 @@ main {
|
|
|
159
168
|
|
|
160
169
|
.PayloadViewer {
|
|
161
170
|
position: sticky;
|
|
162
|
-
top:
|
|
171
|
+
top: 62px;
|
|
163
172
|
width: 50%;
|
|
164
173
|
margin-left: 20px;
|
|
165
174
|
|
|
@@ -260,7 +269,7 @@ main {
|
|
|
260
269
|
|
|
261
270
|
.InternalServerErrorToggler {
|
|
262
271
|
display: flex;
|
|
263
|
-
margin-left:
|
|
272
|
+
margin-left: 8px;
|
|
264
273
|
cursor: pointer;
|
|
265
274
|
|
|
266
275
|
> input {
|
package/src/Dashboard.js
CHANGED
|
@@ -12,6 +12,8 @@ const Strings = {
|
|
|
12
12
|
cookie_disabled_title: 'No cookies specified in Config.cookies',
|
|
13
13
|
delay: 'Delay',
|
|
14
14
|
empty_response_body: '/* Empty Response Body */',
|
|
15
|
+
fallback_server: 'Fallback Server',
|
|
16
|
+
fallback_server_placeholder: 'Type Server Address',
|
|
15
17
|
internal_server_error: 'Internal Server Error',
|
|
16
18
|
mock: 'Mock',
|
|
17
19
|
reset: 'Reset',
|
|
@@ -46,6 +48,7 @@ function init() {
|
|
|
46
48
|
mockaton.listCookies(),
|
|
47
49
|
mockaton.listComments(),
|
|
48
50
|
mockaton.getCorsAllowed(),
|
|
51
|
+
mockaton.getProxyFallback(),
|
|
49
52
|
mockaton.listStaticFiles()
|
|
50
53
|
].map(api => api.then(response => response.ok && response.json())))
|
|
51
54
|
.then(App)
|
|
@@ -59,13 +62,14 @@ function App(apiResponses) {
|
|
|
59
62
|
.render(DevPanel(apiResponses))
|
|
60
63
|
}
|
|
61
64
|
|
|
62
|
-
function DevPanel([brokersByMethod, cookies, comments, corsAllowed, staticFiles]) {
|
|
65
|
+
function DevPanel([brokersByMethod, cookies, comments, corsAllowed, fallbackAddress, staticFiles]) {
|
|
63
66
|
return (
|
|
64
67
|
r('div', null,
|
|
65
68
|
r('menu', null,
|
|
66
69
|
r('img', { src: '/mockaton-logo.svg', width: 160, alt: Strings.title }),
|
|
67
70
|
r(CookieSelector, { list: cookies }),
|
|
68
71
|
r(BulkSelector, { comments }),
|
|
72
|
+
r(ProxyFallbackField, { fallbackAddress }),
|
|
69
73
|
r(CorsCheckbox, { corsAllowed }),
|
|
70
74
|
r(ResetButton)),
|
|
71
75
|
r('main', null,
|
|
@@ -124,6 +128,29 @@ function BulkSelector({ comments }) {
|
|
|
124
128
|
}
|
|
125
129
|
|
|
126
130
|
|
|
131
|
+
function ProxyFallbackField({ fallbackAddress = '' }) {
|
|
132
|
+
function onChange(event) {
|
|
133
|
+
const input = event.currentTarget
|
|
134
|
+
if (!input.validity.valid)
|
|
135
|
+
input.reportValidity()
|
|
136
|
+
else
|
|
137
|
+
mockaton.setProxyFallback(input.value)
|
|
138
|
+
.catch(console.error)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
r('label', null,
|
|
143
|
+
r('span', null, Strings.fallback_server),
|
|
144
|
+
r('input', {
|
|
145
|
+
type: 'url',
|
|
146
|
+
autocomplete: 'none',
|
|
147
|
+
placeholder: Strings.fallback_server_placeholder,
|
|
148
|
+
value: fallbackAddress,
|
|
149
|
+
onChange
|
|
150
|
+
})))
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
|
|
127
154
|
function CorsCheckbox({ corsAllowed }) {
|
|
128
155
|
function onChange(event) {
|
|
129
156
|
mockaton.setCorsAllowed(event.currentTarget.checked)
|
|
@@ -64,6 +64,12 @@ export function sendNotFound(response) {
|
|
|
64
64
|
response.end()
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
export function sendUnprocessableContent(response, error) {
|
|
68
|
+
console.error(error)
|
|
69
|
+
response.statusCode = 422
|
|
70
|
+
response.end(error)
|
|
71
|
+
}
|
|
72
|
+
|
|
67
73
|
export function sendInternalServerError(response, error) {
|
|
68
74
|
console.error(error)
|
|
69
75
|
response.statusCode = 500
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|