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.

30 lines
835 B

4 years ago
  1. var http = require('http');
  2. var sockjs = require('sockjs');
  3. var node_static = require('node-static');
  4. // 1. Echo sockjs server
  5. var sockjs_opts = {sockjs_url: "http://cdn.jsdelivr.net/sockjs/1.0.1/sockjs.min.js"};
  6. var sockjs_echo = sockjs.createServer(sockjs_opts);
  7. sockjs_echo.on('connection', function(conn) {
  8. conn.on('data', function(message) {
  9. conn.write(message);
  10. });
  11. });
  12. // 2. Static files server
  13. var static_directory = new node_static.Server(__dirname);
  14. // 3. Usual http stuff
  15. var server = http.createServer();
  16. server.addListener('request', function(req, res) {
  17. static_directory.serve(req, res);
  18. });
  19. server.addListener('upgrade', function(req,res){
  20. res.end();
  21. });
  22. sockjs_echo.installHandlers(server, {prefix:'/echo'});
  23. console.log(' [*] Listening on 0.0.0.0:9999' );
  24. server.listen(9999, '0.0.0.0');