You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.2 KiB

  1. var http = require('http');
  2. var fs = require('fs');
  3. var connections = 0;
  4. var server = http.createServer(function(req, res) {
  5. var socket = req.socket;
  6. console.log('Request: %s %s -> %s', req.method, req.url, socket.filename);
  7. req.on('end', function() {
  8. if (req.url !== '/') {
  9. res.end(JSON.stringify({
  10. method: req.method,
  11. url: req.url,
  12. filename: socket.filename,
  13. }));
  14. return;
  15. }
  16. res.writeHead(200, {'content-type': 'text/html'});
  17. res.end(
  18. '<form action="/upload" enctype="multipart/form-data" method="post">'+
  19. '<input type="text" name="title"><br>'+
  20. '<input type="file" name="upload" multiple="multiple"><br>'+
  21. '<input type="submit" value="Upload">'+
  22. '</form>'
  23. );
  24. });
  25. });
  26. server.on('connection', function(socket) {
  27. connections++;
  28. socket.id = connections;
  29. socket.filename = 'connection-' + socket.id + '.http';
  30. socket.file = fs.createWriteStream(socket.filename);
  31. socket.pipe(socket.file);
  32. console.log('--> %s', socket.filename);
  33. socket.on('close', function() {
  34. console.log('<-- %s', socket.filename);
  35. });
  36. });
  37. var port = process.env.PORT || 8080;
  38. server.listen(port, function() {
  39. console.log('Recording connections on port %s', port);
  40. });