restful-dummy-server 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.
- package/.idea/modules.xml +8 -0
- package/.idea/restful-dummy-server.iml +9 -0
- package/.idea/vcs.xml +7 -0
- package/README.md +2 -0
- package/default-server-setting.js +12 -0
- package/dist/bundle.js +3 -0
- package/dist/bundle.js.LICENSE.txt +250 -0
- package/index.js +56 -0
- package/package.json +40 -0
- package/server.js +81 -0
- package/utils.js +91 -0
- package/webpack.config.js +24 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* accepts
|
|
3
|
+
* Copyright(c) 2014 Jonathan Ong
|
|
4
|
+
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/*!
|
|
9
|
+
* body-parser
|
|
10
|
+
* Copyright(c) 2014 Jonathan Ong
|
|
11
|
+
* Copyright(c) 2014-2015 Douglas Christopher Wilson
|
|
12
|
+
* MIT Licensed
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/*!
|
|
16
|
+
* body-parser
|
|
17
|
+
* Copyright(c) 2014-2015 Douglas Christopher Wilson
|
|
18
|
+
* MIT Licensed
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/*!
|
|
22
|
+
* bytes
|
|
23
|
+
* Copyright(c) 2012-2014 TJ Holowaychuk
|
|
24
|
+
* Copyright(c) 2015 Jed Watson
|
|
25
|
+
* MIT Licensed
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/*!
|
|
29
|
+
* content-disposition
|
|
30
|
+
* Copyright(c) 2014-2017 Douglas Christopher Wilson
|
|
31
|
+
* MIT Licensed
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/*!
|
|
35
|
+
* content-type
|
|
36
|
+
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
37
|
+
* MIT Licensed
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/*!
|
|
41
|
+
* cookie
|
|
42
|
+
* Copyright(c) 2012-2014 Roman Shtylman
|
|
43
|
+
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
44
|
+
* MIT Licensed
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/*!
|
|
48
|
+
* depd
|
|
49
|
+
* Copyright(c) 2014-2018 Douglas Christopher Wilson
|
|
50
|
+
* MIT Licensed
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
/*!
|
|
54
|
+
* destroy
|
|
55
|
+
* Copyright(c) 2014 Jonathan Ong
|
|
56
|
+
* Copyright(c) 2015-2022 Douglas Christopher Wilson
|
|
57
|
+
* MIT Licensed
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
/*!
|
|
61
|
+
* ee-first
|
|
62
|
+
* Copyright(c) 2014 Jonathan Ong
|
|
63
|
+
* MIT Licensed
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
/*!
|
|
67
|
+
* encodeurl
|
|
68
|
+
* Copyright(c) 2016 Douglas Christopher Wilson
|
|
69
|
+
* MIT Licensed
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
/*!
|
|
73
|
+
* escape-html
|
|
74
|
+
* Copyright(c) 2012-2013 TJ Holowaychuk
|
|
75
|
+
* Copyright(c) 2015 Andreas Lubbe
|
|
76
|
+
* Copyright(c) 2015 Tiancheng "Timothy" Gu
|
|
77
|
+
* MIT Licensed
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
/*!
|
|
81
|
+
* etag
|
|
82
|
+
* Copyright(c) 2014-2016 Douglas Christopher Wilson
|
|
83
|
+
* MIT Licensed
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
/*!
|
|
87
|
+
* express
|
|
88
|
+
* Copyright(c) 2009-2013 TJ Holowaychuk
|
|
89
|
+
* Copyright(c) 2013 Roman Shtylman
|
|
90
|
+
* Copyright(c) 2014-2015 Douglas Christopher Wilson
|
|
91
|
+
* MIT Licensed
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
/*!
|
|
95
|
+
* express
|
|
96
|
+
* Copyright(c) 2009-2013 TJ Holowaychuk
|
|
97
|
+
* Copyright(c) 2014-2015 Douglas Christopher Wilson
|
|
98
|
+
* MIT Licensed
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
/*!
|
|
102
|
+
* finalhandler
|
|
103
|
+
* Copyright(c) 2014-2022 Douglas Christopher Wilson
|
|
104
|
+
* MIT Licensed
|
|
105
|
+
*/
|
|
106
|
+
|
|
107
|
+
/*!
|
|
108
|
+
* forwarded
|
|
109
|
+
* Copyright(c) 2014-2017 Douglas Christopher Wilson
|
|
110
|
+
* MIT Licensed
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
/*!
|
|
114
|
+
* fresh
|
|
115
|
+
* Copyright(c) 2012 TJ Holowaychuk
|
|
116
|
+
* Copyright(c) 2016-2017 Douglas Christopher Wilson
|
|
117
|
+
* MIT Licensed
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
/*!
|
|
121
|
+
* http-errors
|
|
122
|
+
* Copyright(c) 2014 Jonathan Ong
|
|
123
|
+
* Copyright(c) 2016 Douglas Christopher Wilson
|
|
124
|
+
* MIT Licensed
|
|
125
|
+
*/
|
|
126
|
+
|
|
127
|
+
/*!
|
|
128
|
+
* media-typer
|
|
129
|
+
* Copyright(c) 2014 Douglas Christopher Wilson
|
|
130
|
+
* MIT Licensed
|
|
131
|
+
*/
|
|
132
|
+
|
|
133
|
+
/*!
|
|
134
|
+
* merge-descriptors
|
|
135
|
+
* Copyright(c) 2014 Jonathan Ong
|
|
136
|
+
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
137
|
+
* MIT Licensed
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
/*!
|
|
141
|
+
* methods
|
|
142
|
+
* Copyright(c) 2013-2014 TJ Holowaychuk
|
|
143
|
+
* Copyright(c) 2015-2016 Douglas Christopher Wilson
|
|
144
|
+
* MIT Licensed
|
|
145
|
+
*/
|
|
146
|
+
|
|
147
|
+
/*!
|
|
148
|
+
* mime-db
|
|
149
|
+
* Copyright(c) 2014 Jonathan Ong
|
|
150
|
+
* Copyright(c) 2015-2022 Douglas Christopher Wilson
|
|
151
|
+
* MIT Licensed
|
|
152
|
+
*/
|
|
153
|
+
|
|
154
|
+
/*!
|
|
155
|
+
* mime-types
|
|
156
|
+
* Copyright(c) 2014 Jonathan Ong
|
|
157
|
+
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
158
|
+
* MIT Licensed
|
|
159
|
+
*/
|
|
160
|
+
|
|
161
|
+
/*!
|
|
162
|
+
* negotiator
|
|
163
|
+
* Copyright(c) 2012 Federico Romero
|
|
164
|
+
* Copyright(c) 2012-2014 Isaac Z. Schlueter
|
|
165
|
+
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
166
|
+
* MIT Licensed
|
|
167
|
+
*/
|
|
168
|
+
|
|
169
|
+
/*!
|
|
170
|
+
* on-finished
|
|
171
|
+
* Copyright(c) 2013 Jonathan Ong
|
|
172
|
+
* Copyright(c) 2014 Douglas Christopher Wilson
|
|
173
|
+
* MIT Licensed
|
|
174
|
+
*/
|
|
175
|
+
|
|
176
|
+
/*!
|
|
177
|
+
* parseurl
|
|
178
|
+
* Copyright(c) 2014 Jonathan Ong
|
|
179
|
+
* Copyright(c) 2014-2017 Douglas Christopher Wilson
|
|
180
|
+
* MIT Licensed
|
|
181
|
+
*/
|
|
182
|
+
|
|
183
|
+
/*!
|
|
184
|
+
* proxy-addr
|
|
185
|
+
* Copyright(c) 2014-2016 Douglas Christopher Wilson
|
|
186
|
+
* MIT Licensed
|
|
187
|
+
*/
|
|
188
|
+
|
|
189
|
+
/*!
|
|
190
|
+
* range-parser
|
|
191
|
+
* Copyright(c) 2012-2014 TJ Holowaychuk
|
|
192
|
+
* Copyright(c) 2015-2016 Douglas Christopher Wilson
|
|
193
|
+
* MIT Licensed
|
|
194
|
+
*/
|
|
195
|
+
|
|
196
|
+
/*!
|
|
197
|
+
* raw-body
|
|
198
|
+
* Copyright(c) 2013-2014 Jonathan Ong
|
|
199
|
+
* Copyright(c) 2014-2022 Douglas Christopher Wilson
|
|
200
|
+
* MIT Licensed
|
|
201
|
+
*/
|
|
202
|
+
|
|
203
|
+
/*!
|
|
204
|
+
* send
|
|
205
|
+
* Copyright(c) 2012 TJ Holowaychuk
|
|
206
|
+
* Copyright(c) 2014-2022 Douglas Christopher Wilson
|
|
207
|
+
* MIT Licensed
|
|
208
|
+
*/
|
|
209
|
+
|
|
210
|
+
/*!
|
|
211
|
+
* serve-static
|
|
212
|
+
* Copyright(c) 2010 Sencha Inc.
|
|
213
|
+
* Copyright(c) 2011 TJ Holowaychuk
|
|
214
|
+
* Copyright(c) 2014-2016 Douglas Christopher Wilson
|
|
215
|
+
* MIT Licensed
|
|
216
|
+
*/
|
|
217
|
+
|
|
218
|
+
/*!
|
|
219
|
+
* statuses
|
|
220
|
+
* Copyright(c) 2014 Jonathan Ong
|
|
221
|
+
* Copyright(c) 2016 Douglas Christopher Wilson
|
|
222
|
+
* MIT Licensed
|
|
223
|
+
*/
|
|
224
|
+
|
|
225
|
+
/*!
|
|
226
|
+
* toidentifier
|
|
227
|
+
* Copyright(c) 2016 Douglas Christopher Wilson
|
|
228
|
+
* MIT Licensed
|
|
229
|
+
*/
|
|
230
|
+
|
|
231
|
+
/*!
|
|
232
|
+
* type-is
|
|
233
|
+
* Copyright(c) 2014 Jonathan Ong
|
|
234
|
+
* Copyright(c) 2014-2015 Douglas Christopher Wilson
|
|
235
|
+
* MIT Licensed
|
|
236
|
+
*/
|
|
237
|
+
|
|
238
|
+
/*!
|
|
239
|
+
* unpipe
|
|
240
|
+
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
241
|
+
* MIT Licensed
|
|
242
|
+
*/
|
|
243
|
+
|
|
244
|
+
/*!
|
|
245
|
+
* vary
|
|
246
|
+
* Copyright(c) 2014-2017 Douglas Christopher Wilson
|
|
247
|
+
* MIT Licensed
|
|
248
|
+
*/
|
|
249
|
+
|
|
250
|
+
/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
package/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const express = require('express');
|
|
4
|
+
// const yargs = require('yargs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const commander = require('commander');
|
|
7
|
+
|
|
8
|
+
//const app = express();
|
|
9
|
+
const server = require('./server');
|
|
10
|
+
|
|
11
|
+
commander
|
|
12
|
+
.option('-host, --host [host]', 'Specify host.', '')
|
|
13
|
+
.option('-port, --port [port]', 'Specify port.', '')
|
|
14
|
+
.option('-proxy, --proxy [proxy]', 'Specify proxy like "localhost:80".', '')
|
|
15
|
+
.option('-static, --static [static]', 'Specify static files location.', '')
|
|
16
|
+
.option('-config, --config [config]', 'Specify config files location.', '')
|
|
17
|
+
.parse(process.argv);
|
|
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
|
+
const { static, config, port, host, proxy } = commander?.opts();
|
|
49
|
+
|
|
50
|
+
server.start({
|
|
51
|
+
port: port,
|
|
52
|
+
host: host,
|
|
53
|
+
proxy: proxy,
|
|
54
|
+
staticPath: static ? path.resolve(static) : undefined,
|
|
55
|
+
configPath: config ? path.resolve(config) : undefined
|
|
56
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "restful-dummy-server",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "This can be used to mock restful api responses.",
|
|
5
|
+
"main": "dist/bundle.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "rm -rf dist && webpack",
|
|
8
|
+
"publish:package": "npm run build && npm publish --access=public"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"restful-dummy-server": "dist/bundle.js"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/SuneetBansal/restful-dummy-server.git"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"dummy",
|
|
19
|
+
"mock",
|
|
20
|
+
"rest server",
|
|
21
|
+
"restful dummy server",
|
|
22
|
+
"fake"
|
|
23
|
+
],
|
|
24
|
+
"author": "Suneet Bansal",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/SuneetBansal/restful-dummy-server/issues"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/SuneetBansal/restful-dummy-server#readme",
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"commander": "^11.0.0",
|
|
32
|
+
"express": "^4.18.2",
|
|
33
|
+
"express-http-proxy": "^1.6.3"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"rimraf": "^3.0.2",
|
|
37
|
+
"webpack": "^5.75.0",
|
|
38
|
+
"webpack-cli": "^5.0.1"
|
|
39
|
+
}
|
|
40
|
+
}
|
package/server.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// lib imports
|
|
2
|
+
const express = require('express');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const httpProxy = require('express-http-proxy');
|
|
6
|
+
|
|
7
|
+
// custom imports
|
|
8
|
+
const app = express();
|
|
9
|
+
const defaultServerSetting = require('./default-server-setting');
|
|
10
|
+
const utils = require('./utils');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* to start express server with provided configuration
|
|
14
|
+
*
|
|
15
|
+
* @param {*} serverSettings
|
|
16
|
+
*/
|
|
17
|
+
function start(serverSettings) {
|
|
18
|
+
const { staticPath, configPath, ...others } = serverSettings;
|
|
19
|
+
const { port, host, proxy } = others;
|
|
20
|
+
|
|
21
|
+
// merging user server settings with default server settings
|
|
22
|
+
const options = Object.assign({}, defaultServerSetting, serverSettings);
|
|
23
|
+
|
|
24
|
+
app.set('options', options);
|
|
25
|
+
|
|
26
|
+
app.use(function(req, res, next) {
|
|
27
|
+
const result = utils.getMatchingDummyData(req, configPath);
|
|
28
|
+
const { response: defaultResponse } = app.get('options');
|
|
29
|
+
|
|
30
|
+
if (result?.response) {
|
|
31
|
+
const { body, headers: responseHeaders, delay } = result?.response;
|
|
32
|
+
const headers = { ...defaultResponse?.headers, ...responseHeaders };
|
|
33
|
+
|
|
34
|
+
res.set(headers);
|
|
35
|
+
res.status(200);
|
|
36
|
+
|
|
37
|
+
setTimeout(() => {
|
|
38
|
+
try {
|
|
39
|
+
if (typeof body === 'string') {
|
|
40
|
+
const filePath = path.join(configPath, body);
|
|
41
|
+
const fileStat = fs.statSync(filePath);
|
|
42
|
+
|
|
43
|
+
if (fileStat.isFile()) {
|
|
44
|
+
res.sendFile(filePath);
|
|
45
|
+
} else {
|
|
46
|
+
res.send(body);
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
res.send(body);
|
|
50
|
+
}
|
|
51
|
+
} catch (e) {
|
|
52
|
+
res.send(body);
|
|
53
|
+
}
|
|
54
|
+
}, delay ?? 0);
|
|
55
|
+
} else if (proxy) {
|
|
56
|
+
next();
|
|
57
|
+
} else {
|
|
58
|
+
res.status(404);
|
|
59
|
+
res.send({ 'message': 'not found' });
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// adding proxy middleware which would work when no response is found and proxy is configured
|
|
64
|
+
if (proxy) {
|
|
65
|
+
app.use(
|
|
66
|
+
httpProxy(proxy, {
|
|
67
|
+
proxyReqPathResolver: function (req) {
|
|
68
|
+
return req.url;
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
app.listen(port, host, () => {
|
|
75
|
+
console.log('Mock server started at ' + port);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
module.exports = {
|
|
80
|
+
start
|
|
81
|
+
};
|
package/utils.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// lib imports
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
function getMatchingDummyData(req, configPath) {
|
|
6
|
+
let fileList;
|
|
7
|
+
|
|
8
|
+
try {
|
|
9
|
+
fileList = fs.readdirSync(configPath);
|
|
10
|
+
} catch (exception) {
|
|
11
|
+
console.log('There is no file found at ' + configPath);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// checking if fileList is not empty
|
|
15
|
+
if (fileList?.length > 0) {
|
|
16
|
+
let result;
|
|
17
|
+
|
|
18
|
+
for (let index = 0; index < fileList?.length > 0; index ++) {
|
|
19
|
+
const file = fileList[index];
|
|
20
|
+
const filePath = path.join(configPath, file);
|
|
21
|
+
const fileStat = fs.statSync(filePath);
|
|
22
|
+
|
|
23
|
+
if (fileStat.isFile()) {
|
|
24
|
+
result = getItem(req, filePath);
|
|
25
|
+
} else if (fileStat.isDirectory()) {
|
|
26
|
+
getMatchingDummyData(req, filePath);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (result) {
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* To get matching mock data
|
|
38
|
+
*
|
|
39
|
+
* @param req, filePath
|
|
40
|
+
*/
|
|
41
|
+
function getItem(req, filePath) {
|
|
42
|
+
const fileContent = fs.readFileSync(filePath);
|
|
43
|
+
let mockData = [];
|
|
44
|
+
|
|
45
|
+
if (/.json$/.test(filePath)) {
|
|
46
|
+
mockData = JSON.parse(fileContent) ?? [];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (!Array.isArray(mockData)) {
|
|
50
|
+
mockData = [mockData];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return mockData?.find((item) => (isMatchingPathExists(req, item)));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* To check if req path exists on mock data
|
|
58
|
+
*/
|
|
59
|
+
function isMatchingPathExists(req, mockData) {
|
|
60
|
+
let { path, method: reqMethod } = req;
|
|
61
|
+
let { url: mockPath, method: mockMethod } = mockData?.request;
|
|
62
|
+
|
|
63
|
+
// removing starting and trailing /
|
|
64
|
+
path = path.replace(/^\//, '').replace(/\/$/, '');
|
|
65
|
+
mockPath = mockPath.replace(/^\//, '').replace(/\/$/, '');
|
|
66
|
+
|
|
67
|
+
// Below cases supporting -
|
|
68
|
+
// 1. url: /test/:input will match with /test/abc or /test/xyz etc.
|
|
69
|
+
// 2. url: /test/*.* will match with /test/abc.jpg or /test/xyz.png etc.
|
|
70
|
+
// 3. url: /test/**/*.jpg will match with /test/abc.jpg or /test/xyz/abc.jpg or /test/test2/xyg.jpg etc.
|
|
71
|
+
// 4. url: /test/**/*.* will match with /test/test2/xyz.jpg or /test/test2/test3/xyz.png etc.
|
|
72
|
+
const regexForMockPath = mockPath?.replace(/\//g, '\\/')
|
|
73
|
+
.replace(/\./g, '\\.')
|
|
74
|
+
.replace(/\*{2,}/g, '[\\w-\.\/]\+')
|
|
75
|
+
.replace(/\*/g, '[\\w-]\+')
|
|
76
|
+
.replace(/:[\w-\.]+/g, '[\\w-\.]\+');
|
|
77
|
+
const regexEval = eval('/^' + regexForMockPath + '$/'); ;
|
|
78
|
+
|
|
79
|
+
if (reqMethod?.toLowerCase() !== mockMethod?.toLowerCase()) {
|
|
80
|
+
return false;
|
|
81
|
+
} else if (!regexEval?.test(path)) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
module.exports = {
|
|
90
|
+
getMatchingDummyData
|
|
91
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// lib imports
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const webpack = require('webpack');
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
mode: 'production',
|
|
7
|
+
entry: './index.js',
|
|
8
|
+
target: 'node',
|
|
9
|
+
output: {
|
|
10
|
+
filename: 'bundle.js',
|
|
11
|
+
path: path.resolve(__dirname, 'dist'),
|
|
12
|
+
},
|
|
13
|
+
module: {
|
|
14
|
+
rules: [
|
|
15
|
+
{
|
|
16
|
+
test: /\.js$/,
|
|
17
|
+
exclude: /node_modules/,
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
plugins: [
|
|
22
|
+
new webpack.BannerPlugin({ banner: '#!/usr/bin/env node', raw: true }),
|
|
23
|
+
]
|
|
24
|
+
};
|