/
mock.js
64 lines (63 loc) · 1.73 KB
/
mock.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var mocky = require('mocky');
mocky.createServer([{
// simple GET route without request body to match
url: '/profile',
method: 'get',
headers: {'Content-type': 'text/json'},
res: {
status: 200,
headers: {'Content-type': 'text/html', 'Access-Control-Allow-Origin': 'http://localhost:8080'},
body: JSON.stringify({'nickname': ''})
}
},
{
// simple GET route without request body to match
url: '/profile_wait',
method: 'get',
headers: {'Content-type': 'text/json'},
res: function(req, res, callback) {
setTimeout(function() {
callback(null, {
status: 200,
headers: {'Content-type': 'text/html', 'Access-Control-Allow-Origin': 'http://localhost:8080'},
body: JSON.stringify({'nickname': ''})
});
}, 500);
}
},
{
// POST route with request body to match and respose with status, headers and body
url: '/profile',
method: 'post',
req: '',
headers: {'Content-type': 'text/json'},
res: {
status: 200,
headers: {'Content-type': 'text/html', 'Access-Control-Allow-Origin': 'http://localhost:8080'},
body: JSON.stringify({'status': 'ok'})
}
},
{
// PUT route with dynamic response body
url: '/profile',
method: 'put',
req: '',
headers: {'Content-type': 'text/json'},
res: {
status: 200,
headers: {'Content-type': 'text/html', 'Access-Control-Allow-Origin': 'http://localhost:8080'},
body: JSON.stringify({'status': 'ok'})
}
},
{
// DELETE route with dynamic response body
url: '/profile',
method: 'delete',
req: '',
headers: {'Content-type': 'text/json'},
res: {
status: 200,
headers: {'Content-type': 'text/html', 'Access-Control-Allow-Origin': 'http://localhost:8080'},
body: JSON.stringify({'status': 'ok'})
}
}]).listen(4321);