forked from basicallydan/interfake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
regexp-url.js
38 lines (32 loc) · 1.15 KB
/
regexp-url.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
var Interfake = require('..');
var request = require('request');
// Example showing how a regular expression can be used for the URL without using a RegExp type (e.g. you're specifying the endpoints in JSON)
var interfake = new Interfake({ debug: true });
interfake.createRoute({
request: {
url: {
pattern: '/what/the/.*',
regexp: true
},
method: 'get'
},
response: {
code: 200,
body: {
next:'more stuff'
}
}
});
interfake.listen(3030); // The server will listen on port 3030
request('http://localhost:3030/what/the/heck', function (error, response, body) {
console.log(response.statusCode); // prints 200
console.log(body); // prints { "next" : "more stuff" }
});
request('http://localhost:3030/what/the/fuzz', function (error, response, body) {
console.log(response.statusCode); // prints 200
console.log(body); // prints { "next" : "more stuff" }
});
request('http://localhost:3030/what/the/what', function (error, response, body) {
console.log(response.statusCode); // prints 200
console.log(body); // prints { "next" : "more stuff" }
});