Skip to content

Commit a828fe0

Browse files
committed
feat: added status and delay query options; updated bin; handled deprecation warning
1 parent c798a7a commit a828fe0

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

lib/server.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function server (options = {}) {
2020
const app = express()
2121

2222
app.use(bodyParser.json())
23-
app.use(bodyParser.urlencoded())
23+
app.use(bodyParser.urlencoded({extended: true}))
2424
app.use(bodyParser.text())
2525
app.use(bodyParser.raw())
2626

@@ -43,13 +43,24 @@ function server (options = {}) {
4343
(body ? `\n\n${buzJson(body)}` : '')
4444
)
4545

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+
}
5364
})
5465

5566
app.listen(bindPort, () => {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.2.0",
44
"description": "HTTP testing server",
55
"bin": {
6-
"httpbin": "bin/httpbin.js"
6+
"httpbin": "./bin/httpbin.js"
77
},
88
"scripts": {
99
"start": "npm run watch",

0 commit comments

Comments
 (0)