aloy-mock 1.0.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.
Files changed (40) hide show
  1. package/README.md +2 -0
  2. package/app.js +65 -0
  3. package/bin/m2 +22 -0
  4. package/bin/www +91 -0
  5. package/mock/_alive/index.js +8 -0
  6. package/mock/cgi-bin/get-data/index.js +8 -0
  7. package/mock/cgi-bin/rules/select/index.js +8 -0
  8. package/mock/cgi-bin/rules/unselect/index.js +8 -0
  9. package/mock/favicon.ico/index.js +8 -0
  10. package/mock/index.js +8 -0
  11. package/mock/javascripts/jshint/2.13.4/jshint.min.js/index.js +8 -0
  12. package/mock/jian-j/csp-task/external/trade/appoint/getTradeAppointList/index.js +8 -0
  13. package/mock/jian-j/eva-training/external/mock/task/list/index.js +69 -0
  14. package/mock/jian-j/eva-training/external/practice/public/stylesheets/style.css/index.js +8 -0
  15. package/mock/jian-j/eva-training/external/practice/task/create/index.js +9 -0
  16. package/mock/jian-j/eva-training/external/practice/task/detail/index.js +65 -0
  17. package/mock/jian-j/eva-training/external/practice/task/list/index.js +33 -0
  18. package/mock/jian-j/eva-training/external/practice/task/test/index.js +7 -0
  19. package/mock/jian-j/eva-training/external/task/audit/list/index.js +49 -0
  20. package/mock/jian-j/eva-training/external/task/audit/mock/detail/index.js +17 -0
  21. package/mock/jian-j/eva-training/external/task/audit/submit/index.js +8 -0
  22. package/mock/jian-j/favicon.ico/index.js +8 -0
  23. package/mock/jian-j/jian-service/evaluate/arrive/index.js +8 -0
  24. package/mock/jian-j/jian-service/evaluate/forward/index.js +8 -0
  25. package/mock/jian-j/jian-service/evaluate/start/index.js +8 -0
  26. package/mock/jian-j/stylesheets/style.css/index.js +8 -0
  27. package/nodemon.json +17 -0
  28. package/package.json +25 -0
  29. package/public/javascripts/codemirror/5.65.5/codemirror.min.js +2 -0
  30. package/public/javascripts/codemirror/5.65.5/javascript-lint.min.js +2 -0
  31. package/public/javascripts/codemirror/5.65.5/javascript.min.js +2 -0
  32. package/public/javascripts/codemirror/5.65.5/lint.min.js +2 -0
  33. package/public/javascripts/jshint/2.13.4/jshint.min.js +2 -0
  34. package/public/stylesheets/codemirror/5.65.5/codemirror.css +339 -0
  35. package/public/stylesheets/codemirror/5.65.5/lint.css +81 -0
  36. package/public/stylesheets/style.css +31 -0
  37. package/routes/index.js +96 -0
  38. package/views/error.jade +6 -0
  39. package/views/index.jade +83 -0
  40. package/views/layout.jade +9 -0
@@ -0,0 +1,339 @@
1
+ /*https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/codemirror.min.css*/
2
+ /* BASICS */
3
+
4
+ .CodeMirror {
5
+ /* Set height, width, borders, and global font properties here */
6
+ font-family: monospace;
7
+ height: 300px;
8
+ color: black;
9
+ direction: ltr;
10
+ }
11
+
12
+ /* PADDING */
13
+
14
+ .CodeMirror-lines {
15
+ padding: 4px 0; /* Vertical padding around content */
16
+ }
17
+ .CodeMirror pre.CodeMirror-line,
18
+ .CodeMirror pre.CodeMirror-line-like {
19
+ padding: 0 4px; /* Horizontal padding of content */
20
+ }
21
+
22
+ .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
23
+ background-color: white; /* The little square between H and V scrollbars */
24
+ }
25
+
26
+ /* GUTTER */
27
+
28
+ .CodeMirror-gutters {
29
+ border-right: 1px solid #ddd;
30
+ background-color: #f7f7f7;
31
+ white-space: nowrap;
32
+ }
33
+ .CodeMirror-linenumber {
34
+ padding: 0 3px 0 5px;
35
+ min-width: 20px;
36
+ text-align: right;
37
+ color: #999;
38
+ white-space: nowrap;
39
+ }
40
+
41
+ .CodeMirror-guttermarker { color: black; }
42
+ .CodeMirror-guttermarker-subtle { color: #999; }
43
+
44
+ /* CURSOR */
45
+
46
+ .CodeMirror-cursor {
47
+ border-left: 1px solid black;
48
+ border-right: none;
49
+ width: 0;
50
+ }
51
+ /* Shown when moving in bi-directional text */
52
+ .CodeMirror div.CodeMirror-secondarycursor {
53
+ border-left: 1px solid silver;
54
+ }
55
+ .cm-fat-cursor .CodeMirror-cursor {
56
+ width: auto;
57
+ border: 0 !important;
58
+ background: #7e7;
59
+ }
60
+ .cm-fat-cursor div.CodeMirror-cursors {
61
+ z-index: 1;
62
+ }
63
+ .cm-fat-cursor .CodeMirror-line::selection,
64
+ .cm-fat-cursor .CodeMirror-line > span::selection,
65
+ .cm-fat-cursor .CodeMirror-line > span > span::selection { background: transparent; }
66
+ .cm-fat-cursor .CodeMirror-line::-moz-selection,
67
+ .cm-fat-cursor .CodeMirror-line > span::-moz-selection,
68
+ .cm-fat-cursor .CodeMirror-line > span > span::-moz-selection { background: transparent; }
69
+ .cm-fat-cursor { caret-color: transparent; }
70
+ @-moz-keyframes blink {
71
+ 0% {}
72
+ 50% { background-color: transparent; }
73
+ 100% {}
74
+ }
75
+ @-webkit-keyframes blink {
76
+ 0% {}
77
+ 50% { background-color: transparent; }
78
+ 100% {}
79
+ }
80
+ @keyframes blink {
81
+ 0% {}
82
+ 50% { background-color: transparent; }
83
+ 100% {}
84
+ }
85
+
86
+ /* Can style cursor different in overwrite (non-insert) mode */
87
+ .cm-tab { display: inline-block; text-decoration: inherit; }
88
+
89
+ .CodeMirror-rulers {
90
+ position: absolute;
91
+ left: 0; right: 0; top: -50px; bottom: 0;
92
+ overflow: hidden;
93
+ }
94
+ .CodeMirror-ruler {
95
+ border-left: 1px solid #ccc;
96
+ top: 0; bottom: 0;
97
+ position: absolute;
98
+ }
99
+
100
+ /* DEFAULT THEME */
101
+
102
+ .cm-s-default .cm-header {color: blue;}
103
+ .cm-s-default .cm-quote {color: #090;}
104
+ .cm-negative {color: #d44;}
105
+ .cm-positive {color: #292;}
106
+ .cm-header, .cm-strong {font-weight: bold;}
107
+ .cm-em {font-style: italic;}
108
+ .cm-link {text-decoration: underline;}
109
+ .cm-strikethrough {text-decoration: line-through;}
110
+
111
+ .cm-s-default .cm-keyword {color: #708;}
112
+ .cm-s-default .cm-atom {color: #219;}
113
+ .cm-s-default .cm-number {color: #164;}
114
+ .cm-s-default .cm-def {color: #00f;}
115
+ .cm-s-default .cm-variable-2 {color: #05a;}
116
+ .cm-s-default .cm-variable-3, .cm-s-default .cm-type {color: #085;}
117
+ .cm-s-default .cm-comment {color: #a50;}
118
+ .cm-s-default .cm-string {color: #a11;}
119
+ .cm-s-default .cm-string-2 {color: #f50;}
120
+ .cm-s-default .cm-meta {color: #555;}
121
+ .cm-s-default .cm-qualifier {color: #555;}
122
+ .cm-s-default .cm-builtin {color: #30a;}
123
+ .cm-s-default .cm-bracket {color: #997;}
124
+ .cm-s-default .cm-tag {color: #170;}
125
+ .cm-s-default .cm-attribute {color: #00c;}
126
+ .cm-s-default .cm-hr {color: #999;}
127
+ .cm-s-default .cm-link {color: #00c;}
128
+
129
+ .cm-s-default .cm-error {color: #f00;}
130
+ .cm-invalidchar {color: #f00;}
131
+
132
+ .CodeMirror-composing { border-bottom: 2px solid; }
133
+
134
+ /* Default styles for common addons */
135
+
136
+ div.CodeMirror span.CodeMirror-matchingbracket {color: #0b0;}
137
+ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #a22;}
138
+ .CodeMirror-matchingtag { background: rgba(255, 150, 0, .3); }
139
+ .CodeMirror-activeline-background {background: #e8f2ff;}
140
+
141
+ /* STOP */
142
+
143
+ /* The rest of this file contains styles related to the mechanics of
144
+ the editor. You probably shouldn't touch them. */
145
+
146
+ .CodeMirror {
147
+ position: relative;
148
+ overflow: hidden;
149
+ background: white;
150
+ }
151
+
152
+ .CodeMirror-scroll {
153
+ overflow: scroll !important; /* Things will break if this is overridden */
154
+ /* 50px is the magic margin used to hide the element's real scrollbars */
155
+ /* See overflow: hidden in .CodeMirror */
156
+ margin-bottom: -50px; margin-right: -50px;
157
+ padding-bottom: 50px;
158
+ height: 100%;
159
+ outline: none; /* Prevent dragging from highlighting the element */
160
+ position: relative;
161
+ z-index: 0;
162
+ }
163
+ .CodeMirror-sizer {
164
+ position: relative;
165
+ border-right: 50px solid transparent;
166
+ }
167
+
168
+ /* The fake, visible scrollbars. Used to force redraw during scrolling
169
+ before actual scrolling happens, thus preventing shaking and
170
+ flickering artifacts. */
171
+ .CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
172
+ position: absolute;
173
+ z-index: 6;
174
+ display: none;
175
+ outline: none;
176
+ }
177
+ .CodeMirror-vscrollbar {
178
+ right: 0; top: 0;
179
+ overflow-x: hidden;
180
+ overflow-y: scroll;
181
+ }
182
+ .CodeMirror-hscrollbar {
183
+ bottom: 0; left: 0;
184
+ overflow-y: hidden;
185
+ overflow-x: scroll;
186
+ }
187
+ .CodeMirror-scrollbar-filler {
188
+ right: 0; bottom: 0;
189
+ }
190
+ .CodeMirror-gutter-filler {
191
+ left: 0; bottom: 0;
192
+ }
193
+
194
+ .CodeMirror-gutters {
195
+ position: absolute; left: 0; top: 0;
196
+ min-height: 100%;
197
+ z-index: 3;
198
+ }
199
+ .CodeMirror-gutter {
200
+ white-space: normal;
201
+ height: 100%;
202
+ display: inline-block;
203
+ vertical-align: top;
204
+ margin-bottom: -50px;
205
+ }
206
+ .CodeMirror-gutter-wrapper {
207
+ position: absolute;
208
+ z-index: 4;
209
+ background: none !important;
210
+ border: none !important;
211
+ }
212
+ .CodeMirror-gutter-background {
213
+ position: absolute;
214
+ top: 0; bottom: 0;
215
+ z-index: 4;
216
+ }
217
+ .CodeMirror-gutter-elt {
218
+ position: absolute;
219
+ cursor: default;
220
+ z-index: 4;
221
+ }
222
+ .CodeMirror-gutter-wrapper ::selection { background-color: transparent }
223
+ .CodeMirror-gutter-wrapper ::-moz-selection { background-color: transparent }
224
+
225
+ .CodeMirror-lines {
226
+ cursor: text;
227
+ min-height: 1px; /* prevents collapsing before first draw */
228
+ }
229
+ .CodeMirror pre.CodeMirror-line,
230
+ .CodeMirror pre.CodeMirror-line-like {
231
+ /* Reset some styles that the rest of the page might have set */
232
+ -moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0;
233
+ border-width: 0;
234
+ background: transparent;
235
+ font-family: inherit;
236
+ font-size: inherit;
237
+ margin: 0;
238
+ white-space: pre;
239
+ word-wrap: normal;
240
+ line-height: inherit;
241
+ color: inherit;
242
+ z-index: 2;
243
+ position: relative;
244
+ overflow: visible;
245
+ -webkit-tap-highlight-color: transparent;
246
+ -webkit-font-variant-ligatures: contextual;
247
+ font-variant-ligatures: contextual;
248
+ }
249
+ .CodeMirror-wrap pre.CodeMirror-line,
250
+ .CodeMirror-wrap pre.CodeMirror-line-like {
251
+ word-wrap: break-word;
252
+ white-space: pre-wrap;
253
+ word-break: normal;
254
+ }
255
+
256
+ .CodeMirror-linebackground {
257
+ position: absolute;
258
+ left: 0; right: 0; top: 0; bottom: 0;
259
+ z-index: 0;
260
+ }
261
+
262
+ .CodeMirror-linewidget {
263
+ position: relative;
264
+ z-index: 2;
265
+ padding: 0.1px; /* Force widget margins to stay inside of the container */
266
+ }
267
+
268
+ .CodeMirror-widget {}
269
+
270
+ .CodeMirror-rtl pre { direction: rtl; }
271
+
272
+ .CodeMirror-code {
273
+ outline: none;
274
+ }
275
+
276
+ /* Force content-box sizing for the elements where we expect it */
277
+ .CodeMirror-scroll,
278
+ .CodeMirror-sizer,
279
+ .CodeMirror-gutter,
280
+ .CodeMirror-gutters,
281
+ .CodeMirror-linenumber {
282
+ -moz-box-sizing: content-box;
283
+ box-sizing: content-box;
284
+ }
285
+
286
+ .CodeMirror-measure {
287
+ position: absolute;
288
+ width: 100%;
289
+ height: 0;
290
+ overflow: hidden;
291
+ visibility: hidden;
292
+ }
293
+
294
+ .CodeMirror-cursor {
295
+ position: absolute;
296
+ pointer-events: none;
297
+ }
298
+ .CodeMirror-measure pre { position: static; }
299
+
300
+ div.CodeMirror-cursors {
301
+ visibility: hidden;
302
+ position: relative;
303
+ z-index: 3;
304
+ }
305
+ div.CodeMirror-dragcursors {
306
+ visibility: visible;
307
+ }
308
+
309
+ .CodeMirror-focused div.CodeMirror-cursors {
310
+ visibility: visible;
311
+ }
312
+
313
+ .CodeMirror-selected { background: #d9d9d9; }
314
+ .CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
315
+ .CodeMirror-crosshair { cursor: crosshair; }
316
+ .CodeMirror-line::selection, .CodeMirror-line > span::selection, .CodeMirror-line > span > span::selection { background: #d7d4f0; }
317
+ .CodeMirror-line::-moz-selection, .CodeMirror-line > span::-moz-selection, .CodeMirror-line > span > span::-moz-selection { background: #d7d4f0; }
318
+
319
+ .cm-searching {
320
+ background-color: #ffa;
321
+ background-color: rgba(255, 255, 0, .4);
322
+ }
323
+
324
+ /* Used to force a border model for a node */
325
+ .cm-force-border { padding-right: .1px; }
326
+
327
+ @media print {
328
+ /* Hide the cursor when printing */
329
+ .CodeMirror div.CodeMirror-cursors {
330
+ visibility: hidden;
331
+ }
332
+ }
333
+
334
+ /* See issue #2901 */
335
+ .cm-tab-wrap-hack:after { content: ''; }
336
+
337
+ /* Help users use markselection to safely style text background */
338
+ span.CodeMirror-selectedtext { background: none; }
339
+
@@ -0,0 +1,81 @@
1
+ /* https://cdn.bootcdn.net/ajax/libs/codemirror/5.65.5/addon/lint/lint.min.css */
2
+ /* The lint marker gutter */
3
+ .CodeMirror-lint-markers {
4
+ width: 16px;
5
+ }
6
+
7
+ .CodeMirror-lint-tooltip {
8
+ background-color: #ffd;
9
+ border: 1px solid black;
10
+ border-radius: 4px 4px 4px 4px;
11
+ color: black;
12
+ font-family: monospace;
13
+ font-size: 10pt;
14
+ overflow: hidden;
15
+ padding: 2px 5px;
16
+ position: fixed;
17
+ white-space: pre;
18
+ white-space: pre-wrap;
19
+ z-index: 100;
20
+ max-width: 600px;
21
+ opacity: 0;
22
+ transition: opacity .4s;
23
+ -moz-transition: opacity .4s;
24
+ -webkit-transition: opacity .4s;
25
+ -o-transition: opacity .4s;
26
+ -ms-transition: opacity .4s;
27
+ }
28
+
29
+ .CodeMirror-lint-mark {
30
+ background-position: left bottom;
31
+ background-repeat: repeat-x;
32
+ }
33
+
34
+ .CodeMirror-lint-mark-warning {
35
+ background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAYAAAC09K7GAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJFhQXEbhTg7YAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAMklEQVQI12NkgIIvJ3QXMjAwdDN+OaEbysDA4MPAwNDNwMCwiOHLCd1zX07o6kBVGQEAKBANtobskNMAAAAASUVORK5CYII=");
36
+ }
37
+
38
+ .CodeMirror-lint-mark-error {
39
+ background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAYAAAC09K7GAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJDw4cOCW1/KIAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAHElEQVQI12NggIL/DAz/GdA5/xkY/qPKMDAwAADLZwf5rvm+LQAAAABJRU5ErkJggg==");
40
+ }
41
+
42
+ .CodeMirror-lint-marker {
43
+ background-position: center center;
44
+ background-repeat: no-repeat;
45
+ cursor: pointer;
46
+ display: inline-block;
47
+ height: 16px;
48
+ width: 16px;
49
+ vertical-align: middle;
50
+ position: relative;
51
+ }
52
+
53
+ .CodeMirror-lint-message {
54
+ padding-left: 18px;
55
+ background-position: top left;
56
+ background-repeat: no-repeat;
57
+ }
58
+
59
+ .CodeMirror-lint-marker-warning, .CodeMirror-lint-message-warning {
60
+ background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAANlBMVEX/uwDvrwD/uwD/uwD/uwD/uwD/uwD/uwD/uwD6twD/uwAAAADurwD2tQD7uAD+ugAAAAD/uwDhmeTRAAAADHRSTlMJ8mN1EYcbmiixgACm7WbuAAAAVklEQVR42n3PUQqAIBBFUU1LLc3u/jdbOJoW1P08DA9Gba8+YWJ6gNJoNYIBzAA2chBth5kLmG9YUoG0NHAUwFXwO9LuBQL1giCQb8gC9Oro2vp5rncCIY8L8uEx5ZkAAAAASUVORK5CYII=");
61
+ }
62
+
63
+ .CodeMirror-lint-marker-error, .CodeMirror-lint-message-error {
64
+ background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAHlBMVEW7AAC7AACxAAC7AAC7AAAAAAC4AAC5AAD///+7AAAUdclpAAAABnRSTlMXnORSiwCK0ZKSAAAATUlEQVR42mWPOQ7AQAgDuQLx/z8csYRmPRIFIwRGnosRrpamvkKi0FTIiMASR3hhKW+hAN6/tIWhu9PDWiTGNEkTtIOucA5Oyr9ckPgAWm0GPBog6v4AAAAASUVORK5CYII=");
65
+ }
66
+
67
+ .CodeMirror-lint-marker-multiple {
68
+ background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAcAAAAHCAMAAADzjKfhAAAACVBMVEUAAAAAAAC/v7914kyHAAAAAXRSTlMAQObYZgAAACNJREFUeNo1ioEJAAAIwmz/H90iFFSGJgFMe3gaLZ0od+9/AQZ0ADosbYraAAAAAElFTkSuQmCC");
69
+ background-repeat: no-repeat;
70
+ background-position: right bottom;
71
+ width: 100%; height: 100%;
72
+ }
73
+
74
+ .CodeMirror-lint-line-error {
75
+ background-color: rgba(183, 76, 81, 0.08);
76
+ }
77
+
78
+ .CodeMirror-lint-line-warning {
79
+ background-color: rgba(255, 211, 0, 0.1);
80
+ }
81
+
@@ -0,0 +1,31 @@
1
+ a {
2
+ color: #00B7FF;
3
+ }
4
+ .code-editor-wrap {
5
+ display:flex;
6
+ flex:1;
7
+ flex-direction:column;
8
+ overflow:auto;
9
+ }
10
+ .code-editor-submit {
11
+ position: fixed;
12
+ right: 12px;
13
+ top: 12px;
14
+ background-color: #1677ff;
15
+ z-index: 9999;
16
+ border: none;
17
+ color: #fff;
18
+ border-radius: 4px;
19
+ font-size: 12px;
20
+ padding: 4px 12px;
21
+ cursor: pointer;
22
+ }
23
+ .code-editor-submit-disabled {
24
+ cursor: not-allowed;
25
+ color: rgba(0, 0, 0, 0.25);
26
+ background-color: rgba(0, 0, 0, 0.04);
27
+ }
28
+ .code-editor-wrap .CodeMirror{
29
+ flex: 1;
30
+ height: auto;
31
+ }
@@ -0,0 +1,96 @@
1
+ const express = require('express');
2
+ const fs = require('fs').promises;
3
+ const path = require('path');
4
+
5
+ const router = express.Router();
6
+
7
+ const TEMPLATE = `module.exports = ({ method, query, params, body }) => {
8
+ return {
9
+ code: 0,
10
+ data: {
11
+ },
12
+ message: '',
13
+ }
14
+ }`;
15
+
16
+ const delay = (fn) => (...args) => {
17
+ return new Promise(resolve => {
18
+ setTimeout(() => {
19
+ resolve(fn.apply(null, args));
20
+ }, Math.random * 1000);
21
+ });
22
+ };
23
+
24
+ const getFilePath = (dir) => path.resolve(__dirname, dir, 'index.js');
25
+
26
+ async function writeFile(filePath, content) {
27
+ try {
28
+ await fs.access(filePath);
29
+ return;
30
+ } catch (error) {
31
+ const dirPath = path.dirname(filePath);
32
+ try {
33
+ await fs.mkdir(dirPath, { recursive: true });
34
+ } catch (mkdirError) {
35
+ // 如果文件夹创建失败,可能是文件夹已存在
36
+ if (mkdirError.code !== 'EEXIST') {
37
+ throw mkdirError;
38
+ }
39
+ }
40
+ }
41
+ return await fs.writeFile(filePath, content || TEMPLATE, 'utf8');
42
+ }
43
+
44
+ async function navigateHandler(req, res, filePath) {
45
+ let content = '';
46
+ try {
47
+ content = await fs.readFile(filePath, 'utf-8');
48
+ } catch(e) {
49
+ }
50
+ if (!content) {
51
+ content = TEMPLATE;
52
+ await writeFile(filePath, content);
53
+ }
54
+ res.render('index', {
55
+ title: '',
56
+ content,
57
+ });
58
+ };
59
+
60
+ const handler = async (req, res) => {
61
+ const headers = req.headers;
62
+ const fileDir = `../mock${req.path}`;
63
+ const filePath = getFilePath(fileDir);
64
+ if (headers['sec-fetch-mode'] === 'navigate' || !headers.referer) {
65
+ navigateHandler(req, res, filePath);
66
+ return;
67
+ }
68
+ const { type, value = '' } = req.body || {};
69
+ if (type === res.locals.HANDLE_TYPE) {
70
+ let content = value.trim();
71
+ if (!content.replace(/\s*[\n\t][;]?\s*/g, '')) {
72
+ content = TEMPLATE;
73
+ }
74
+ await fs.writeFile(filePath, content, 'utf-8');
75
+ res.json({ code: 0 });
76
+ return;
77
+ }
78
+ await writeFile(filePath);
79
+ try {
80
+ const data = await fs.readFile(filePath, 'utf-8');
81
+ if (/^\s*{[\s\S]*}\s*$/.test(data)) {
82
+ res.json(JSON.parse(data));
83
+ return;
84
+ }
85
+ } catch(e) {
86
+ res.json(e);
87
+ return;
88
+ }
89
+ res.json(await delay(require(fileDir))(req));
90
+ };
91
+
92
+ router.get('/*', handler);
93
+ router.post('/*', handler);
94
+
95
+ module.exports = router;
96
+
@@ -0,0 +1,6 @@
1
+ extends layout
2
+
3
+ block content
4
+ h1= message
5
+ h2= error.status
6
+ pre #{error.stack}
@@ -0,0 +1,83 @@
1
+ extends layout
2
+
3
+ block content
4
+ form(id="mock-server-submit", method="post", style="display:flex;flex-direction:column;height:100vh;overflow:hidden;")
5
+ input(type="submit", id="mock-server-submit-btn", value="保存", class="code-editor-submit")
6
+ div(class="code-editor-wrap")
7
+ textarea(name="code", id="codeEditor")!= content
8
+ script(src="#{PUBLIC_PATH}/javascripts/codemirror/5.65.5/codemirror.min.js")
9
+ script(src="#{PUBLIC_PATH}/javascripts/codemirror/5.65.5/javascript.min.js")
10
+ script(src="#{PUBLIC_PATH}/javascripts/jshint/2.13.4/jshint.min.js")
11
+ script(src="#{PUBLIC_PATH}/javascripts/codemirror/5.65.5/lint.min.js")
12
+ script(src="#{PUBLIC_PATH}/javascripts/codemirror/5.65.5/javascript-lint.min.js")
13
+ script.
14
+ // 初始化 CodeMirror 编辑器
15
+ var editor = CodeMirror.fromTextArea(document.getElementById('codeEditor'), {
16
+ lineNumbers: true,
17
+ mode: "javascript",
18
+ lint: {
19
+ asi: true,
20
+ esversion: 6,
21
+ },
22
+ gutters: ["CodeMirror-lint-markers"],
23
+ });
24
+ var isSave = false;
25
+ var form = document.getElementById('mock-server-submit');
26
+ var content = editor.getValue();
27
+ var save = function(event) {
28
+ // 阻止表单的默认提交行为
29
+ if (isSave) {
30
+ return;
31
+ }
32
+ var errors = window.JSHINT.errors;
33
+ var len = errors.length;
34
+ if (len) {
35
+ for (var i = 0; i < len; i++) {
36
+ var code = errors[i].code;
37
+ if (/^E/.test(code)) {
38
+ return;
39
+ }
40
+ }
41
+ }
42
+ var value = editor.getValue();
43
+ if (content === value) {
44
+ return;
45
+ }
46
+ var saveBtn = document.getElementById('mock-server-submit-btn');
47
+ var disabledClassName = 'code-editor-submit-disabled';
48
+ saveBtn.classList.add(disabledClassName);
49
+ isSave = true;
50
+ fetch(window.location.href, {
51
+ method: 'POST',
52
+ headers: {
53
+ 'Content-Type': 'application/json'
54
+ },
55
+ body: JSON.stringify({
56
+ type: '#{HANDLE_TYPE}',
57
+ value: value || ''
58
+ })
59
+ }).then(function(response){
60
+ return response.json();
61
+ }).then(function(){
62
+ content = value;
63
+ }).catch(function(error){
64
+ console.error(error);
65
+ }).then(function(){
66
+ isSave = false;
67
+ saveBtn.classList.remove(disabledClassName);
68
+ });
69
+ };
70
+ editor.on('blur', save);
71
+ document.addEventListener('keydown', function(event) {
72
+ const isCtrl = event.ctrlKey || event.metaKey;
73
+ if (isCtrl && event.key === 's' || event.code === 'KeyS') {
74
+ // 执行保存操作
75
+ event.preventDefault(); // 阻止默认行为,如浏览器的保存页面对话框
76
+ save();
77
+ }
78
+ });
79
+ form.onsubmit = function(event) {
80
+ // 阻止表单的默认提交行为
81
+ event.preventDefault();
82
+ save();
83
+ };
@@ -0,0 +1,9 @@
1
+ doctype html
2
+ html
3
+ head
4
+ title= title
5
+ link(rel='stylesheet', href="#{PUBLIC_PATH}/stylesheets/style.css")
6
+ link(rel="stylesheet", href="#{PUBLIC_PATH}/stylesheets/codemirror/5.65.5/codemirror.css")
7
+ link(rel="stylesheet" href="#{PUBLIC_PATH}/stylesheets/codemirror/5.65.5/lint.css")
8
+ body
9
+ block content