File tree Expand file tree Collapse file tree 2 files changed +20
-9
lines changed Expand file tree Collapse file tree 2 files changed +20
-9
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ function server (options = {}) {
20
20
const app = express ( )
21
21
22
22
app . use ( bodyParser . json ( ) )
23
- app . use ( bodyParser . urlencoded ( ) )
23
+ app . use ( bodyParser . urlencoded ( { extended : true } ) )
24
24
app . use ( bodyParser . text ( ) )
25
25
app . use ( bodyParser . raw ( ) )
26
26
@@ -43,13 +43,24 @@ function server (options = {}) {
43
43
( body ? `\n\n${ buzJson ( body ) } ` : '' )
44
44
)
45
45
46
- res . json ( {
47
- method,
48
- path,
49
- headers,
50
- query,
51
- body
52
- } )
46
+ const status = Number ( query . status ) || 200
47
+ const delay = Number ( query . delay ) || 0
48
+
49
+ const respond = ( ) => {
50
+ res . status ( status ) . json ( {
51
+ method,
52
+ path,
53
+ headers,
54
+ query,
55
+ body
56
+ } )
57
+ }
58
+
59
+ if ( delay > 0 ) {
60
+ setTimeout ( respond , delay )
61
+ } else {
62
+ respond ( )
63
+ }
53
64
} )
54
65
55
66
app . listen ( bindPort , ( ) => {
Original file line number Diff line number Diff line change 3
3
"version" : " 1.2.0" ,
4
4
"description" : " HTTP testing server" ,
5
5
"bin" : {
6
- "httpbin" : " bin/httpbin.js"
6
+ "httpbin" : " ./ bin/httpbin.js"
7
7
},
8
8
"scripts" : {
9
9
"start" : " npm run watch" ,
You can’t perform that action at this time.
0 commit comments