dummy-http-server.js
868 Bytes
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
39
40
41
42
43
44
#!/usr/bin/env node
"use strict";
/*eslint no-console: "off" */
const express = require('express')
const app = express();
const argv = require('yargs').argv
const port = argv.port || 8080;
app.use(function(req, res, next) {
if (req.path === '/favicon.ico') {
res.end('');
return;
}
console.log('');
console.log('** Incoming request from ' + req.ip);
console.log('Path: ' + req.path);
next();
})
app.get('/', function(req, res, next) {
console.log('Method: GET');
console.log('Query string:', JSON.stringify(req.query, null, 2));
next();
})
app.post('/', function(req, res, next) {
console.log('Method: POST');
console.log('Body: ' + req.body);
next();
})
app.use(function(req, res) {
res.end('');
})
app.listen(port, () => {
console.log('Dummy HTTP server listen on port ' + port);
})