-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
88 lines (75 loc) · 1.92 KB
/
Copy pathindex.js
File metadata and controls
88 lines (75 loc) · 1.92 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
var app = require('express')();
var bodyParser = require('body-parser');
var cors = require('cors');
var http = require('http').Server(app);
var io = require('socket.io')(http);
var port = process.env.PORT || 3000;
app.use(bodyParser.json());
app.use(cors());
app.get('/', function(req, res) {
res.sendFile(__dirname + '/index.html');
});
function emit(req, method) {
console.log("new request");
var now = new Date();
var info = {
timestamp: now.toUTCString(),
url: req.originalUrl,
method: method,
body: req.body,
headers: req.headers
};
io.emit('request', JSON.stringify(info, null, 2));
return info;
}
app.get('/echo/*', function(req, res) {
res.send(emit(req, "get"));
});
app.post('/echo/*', function(req, res) {
res.send(emit(req, "post"));
});
app.put('/echo/*', function(req, res) {
res.send(emit(req, "put"));
});
app.patch('/echo/*', function(req, res) {
res.send(emit(req, "patch"));
});
app.delete('/echo/*', function(req, res) {
res.send(emit(req, "delete"));
});
app.copy('/echo/*', function(req, res) {
res.send(emit(req, "copy"));
});
app.head('/echo/*', function(req, res) {
res.send(emit(req, "head"));
});
app.options('/echo/*', function(req, res) {
res.send(emit(req, "options"));
});
app.link('/echo/*', function(req, res) {
res.send(emit(req, "link"));
});
app.unlink('/echo/*', function(req, res) {
res.send(emit(req, "unlink"));
});
app.purge('/echo/*', function(req, res) {
res.send(emit(req, "purge"));
});
app.lock('/echo/*', function(req, res) {
res.send(emit(req, "lock"));
});
app.unlock('/echo/*', function(req, res) {
res.send(emit(req, "unlock"));
});
app.propfind('/echo/*', function(req, res) {
res.send(emit(req, "propfind"));
});
io.on('connection', function(socket) {
console.log("new client");
socket.on('request', function(info) {
io.emit('request', info);
});
});
http.listen(port, function() {
console.log('listening on *:' + port);
});