restful-dummy-server 1.0.1 → 1.0.3
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.md +158 -1
- package/{index.js → dist/index.js} +3 -32
- package/package.json +40 -41
- package/dist/bundle.js +0 -2
- package/webpack.config.js +0 -33
- /package/{default-server-setting.js → dist/default-server-setting.js} +0 -0
- /package/{server.js → dist/server.js} +0 -0
- /package/{utils.js → dist/utils.js} +0 -0
package/README.md
CHANGED
|
@@ -2,4 +2,161 @@
|
|
|
2
2
|
This can be used to mock Rest API responses.
|
|
3
3
|
|
|
4
4
|
## How to install
|
|
5
|
-
npm install -g restful-dummy-server
|
|
5
|
+
npm install -g restful-dummy-server
|
|
6
|
+
|
|
7
|
+
## How to use
|
|
8
|
+
### CLI options
|
|
9
|
+
|
|
10
|
+
#### 1. port
|
|
11
|
+
"scripts": {
|
|
12
|
+
"start": "restful-dummy-server -port 4000"
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
This will start restful dummy server on port 4000
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
#### 2. host
|
|
19
|
+
You can also mention host.
|
|
20
|
+
"scripts": {
|
|
21
|
+
"start": "restful-dummy-server -port 4000 -host xx.xx.xx.xx"
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
#### 3. static
|
|
25
|
+
"scripts": {
|
|
26
|
+
"start": "restful-dummy-server -port 4000 -static ./data"
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
**static** is used to know the relative path of a folder where all statics files are hosted. Which then would be used by Dummy server to download files against the rest api dowbloaded request.
|
|
30
|
+
Here this folder is **data**.
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
#### 4. config
|
|
34
|
+
"scripts": {
|
|
35
|
+
"start": "restful-dummy-server -port 4000 -static ./data -config ./test"
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
**config** is used to know the relative path of a folder which are having dummy request response instruction files in **.json** extensions only.
|
|
39
|
+
|
|
40
|
+
Note -
|
|
41
|
+
1. Assuming **port** is 4000 for all below examples.
|
|
42
|
+
2. **data** folder is having **test.png** file
|
|
43
|
+
|
|
44
|
+
Example 1-
|
|
45
|
+
**test/config.json**
|
|
46
|
+
|
|
47
|
+
[{
|
|
48
|
+
"request": {
|
|
49
|
+
"url": "/get/message",
|
|
50
|
+
"method": "get"
|
|
51
|
+
},
|
|
52
|
+
"response": {
|
|
53
|
+
"headers": {},
|
|
54
|
+
"body": "Hello Dummy Server"
|
|
55
|
+
}
|
|
56
|
+
}]
|
|
57
|
+
|
|
58
|
+
In this case if you hit http://localhost:5000/get/message then you will get **Hello Dummy Server** as response.
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
Example 2-
|
|
62
|
+
**test/config.json**
|
|
63
|
+
|
|
64
|
+
[{
|
|
65
|
+
"request": {
|
|
66
|
+
"url": "/get/:message",
|
|
67
|
+
"method": "get"
|
|
68
|
+
},
|
|
69
|
+
"response": {
|
|
70
|
+
"headers": {},
|
|
71
|
+
"body": { "message": "Hello Dummy Server" }
|
|
72
|
+
}
|
|
73
|
+
}]
|
|
74
|
+
|
|
75
|
+
In this case if you hit http://localhost:5000/get/test or http://localhost:5000/get/msg etc. then you will get **{ "message": "Hello Dummy Server" }** as response.
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
Example 3-
|
|
79
|
+
**test/config.json**
|
|
80
|
+
|
|
81
|
+
[{
|
|
82
|
+
"request": {
|
|
83
|
+
"url": "/get/png/*.*",
|
|
84
|
+
"method": "get"
|
|
85
|
+
},
|
|
86
|
+
"response": {
|
|
87
|
+
"headers": {
|
|
88
|
+
"Content-Disposition": "attachment;filename= test.png;"
|
|
89
|
+
},
|
|
90
|
+
"body": "./test.png"
|
|
91
|
+
}
|
|
92
|
+
}]
|
|
93
|
+
|
|
94
|
+
In this case if you hit http://localhost:5000/get/png/abc.png or http://localhost:5000/get/png/msg.png etc. then **test.png** will be downloaded as response.
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
Example 4-
|
|
98
|
+
**test/config.json**
|
|
99
|
+
|
|
100
|
+
[{
|
|
101
|
+
"request": {
|
|
102
|
+
"url": "/get/**/*.*",
|
|
103
|
+
"method": "get"
|
|
104
|
+
},
|
|
105
|
+
"response": {
|
|
106
|
+
"headers": {
|
|
107
|
+
"Content-Disposition": "attachment;filename= test.png;"
|
|
108
|
+
},
|
|
109
|
+
"body": "./test.png"
|
|
110
|
+
}
|
|
111
|
+
}]
|
|
112
|
+
|
|
113
|
+
In this case if you hit http://localhost:5000/get/png/abc.png or http://localhost:5000/get/png/png2/msg.jpeg etc. then **test.png** will be downloaded as response.
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
Example 5-
|
|
117
|
+
**test/config.json**
|
|
118
|
+
|
|
119
|
+
[{
|
|
120
|
+
"request": {
|
|
121
|
+
"url": "/get/**/*.png",
|
|
122
|
+
"method": "get"
|
|
123
|
+
},
|
|
124
|
+
"response": {
|
|
125
|
+
"headers": {
|
|
126
|
+
"Content-Disposition": "attachment;filename= test.png;"
|
|
127
|
+
},
|
|
128
|
+
"body": "./test.png"
|
|
129
|
+
}
|
|
130
|
+
}]
|
|
131
|
+
|
|
132
|
+
In this case if you hit http://localhost:5000/get/png/abc.png or http://localhost:5000/get/png/png2/msg.png etc. then **test.png** will be downloaded as response.
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
Example 6-
|
|
136
|
+
**test/config.json**
|
|
137
|
+
|
|
138
|
+
[{
|
|
139
|
+
"request": {
|
|
140
|
+
"url": "/get/**/*.png",
|
|
141
|
+
"method": "get"
|
|
142
|
+
},
|
|
143
|
+
"response": {
|
|
144
|
+
"headers": {
|
|
145
|
+
"Content-Disposition": "attachment;filename= test.png;"
|
|
146
|
+
},
|
|
147
|
+
"body": "./test.png",
|
|
148
|
+
"delay": 2000
|
|
149
|
+
}
|
|
150
|
+
}]
|
|
151
|
+
|
|
152
|
+
Above **delay** is the special attribute which would cause Dummy server to respond in 2000 milliseconds.
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
#### 5. proxy
|
|
156
|
+
"scripts": {
|
|
157
|
+
"start": "restful-dummy-server -port 4000 -static ./data -config ./test -proxy localhost:2000"
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
If **proxy** is provided then Dummy server will redirect the request to the proxy server if there is no matching record found.
|
|
161
|
+
|
|
162
|
+
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
// lib imports
|
|
3
4
|
const express = require('express');
|
|
4
|
-
// const yargs = require('yargs');
|
|
5
5
|
const path = require('path');
|
|
6
6
|
const commander = require('commander');
|
|
7
7
|
|
|
8
|
-
//
|
|
8
|
+
// custom imports
|
|
9
9
|
const server = require('./server');
|
|
10
10
|
|
|
11
11
|
commander
|
|
@@ -16,35 +16,6 @@ commander
|
|
|
16
16
|
.option('-config, --config [config]', 'Specify config files location.', '')
|
|
17
17
|
.parse(process.argv);
|
|
18
18
|
|
|
19
|
-
// const { static, config, port, host, proxy } = yargs
|
|
20
|
-
// .usage('mock-server [options]')
|
|
21
|
-
// .options({
|
|
22
|
-
// host: {
|
|
23
|
-
// alias: 'h',
|
|
24
|
-
// description: 'Set host'
|
|
25
|
-
// },
|
|
26
|
-
// port: {
|
|
27
|
-
// alias: 'P',
|
|
28
|
-
// description: 'Set port'
|
|
29
|
-
// },
|
|
30
|
-
// proxy: {
|
|
31
|
-
// alias: 'p',
|
|
32
|
-
// description: 'Set proxy'
|
|
33
|
-
// },
|
|
34
|
-
// watch: {
|
|
35
|
-
// alias: 'w',
|
|
36
|
-
// description: 'Watch files'
|
|
37
|
-
// },
|
|
38
|
-
// static: {
|
|
39
|
-
// alias: 's',
|
|
40
|
-
// description: 'Static files path'
|
|
41
|
-
// },
|
|
42
|
-
// config: {
|
|
43
|
-
// alias: 'c',
|
|
44
|
-
// description: 'Config file path'
|
|
45
|
-
// }
|
|
46
|
-
// }).argv;
|
|
47
|
-
|
|
48
19
|
const { static, config, port, host, proxy } = commander?.opts();
|
|
49
20
|
|
|
50
21
|
server.start({
|
package/package.json
CHANGED
|
@@ -1,41 +1,40 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "restful-dummy-server",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "This can be used to mock restful api responses.",
|
|
5
|
-
"main": "dist/
|
|
6
|
-
"scripts": {
|
|
7
|
-
"build": "rm -rf dist &&
|
|
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
|
-
"express
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "restful-dummy-server",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "This can be used to mock restful api responses.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "rm -rf dist && cpx \"src/*\" dist",
|
|
8
|
+
"postbuild": "rm -rf src",
|
|
9
|
+
"publish:package": "npm run build && npm publish --access=public"
|
|
10
|
+
},
|
|
11
|
+
"bin": {
|
|
12
|
+
"restful-dummy-server": "dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/SuneetBansal/restful-dummy-server.git"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"dummy",
|
|
20
|
+
"mock",
|
|
21
|
+
"rest server",
|
|
22
|
+
"restful dummy server",
|
|
23
|
+
"fake"
|
|
24
|
+
],
|
|
25
|
+
"author": "Suneet Bansal",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/SuneetBansal/restful-dummy-server/issues"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/SuneetBansal/restful-dummy-server#readme",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"commander": "^11.0.0",
|
|
33
|
+
"express": "^4.18.2",
|
|
34
|
+
"express-http-proxy": "^1.6.3"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"cpx": "^1.5.0",
|
|
38
|
+
"rimraf": "^3.0.2"
|
|
39
|
+
}
|
|
40
|
+
}
|