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.

42 lines
997 B

4 years ago
  1. /**
  2. * Created by Tony on 11/1/13.
  3. */
  4. var http = require('http');
  5. var sockjs = require('sockjs');
  6. var Hapi = require('hapi');
  7. // 1. Echo sockjs server
  8. var sockjs_opts = {
  9. sockjs_url: "http://cdn.jsdelivr.net/sockjs/1.0.1/sockjs.min.js"
  10. };
  11. var sockjs_echo = sockjs.createServer(sockjs_opts);
  12. sockjs_echo.on('connection', function(conn) {
  13. conn.on('data', function(message) {
  14. conn.write(message);
  15. });
  16. });
  17. // Create a server and set port (default host 0.0.0.0)
  18. var hapi_server = new Hapi.Server();
  19. hapi_server.connection({
  20. port: 9999
  21. });
  22. hapi_server.register(require('inert'), (err) => {
  23. hapi_server.route({
  24. method: 'GET',
  25. path: '/{path*}',
  26. handler: function(request, reply) {
  27. reply.file('./html/index.html');
  28. }
  29. });
  30. });
  31. //hapi_server.listener is the http listener hapi uses
  32. sockjs_echo.installHandlers(hapi_server.listener, {
  33. prefix: '/echo'
  34. });
  35. console.log(' [*] Listening on 0.0.0.0:9999');
  36. hapi_server.start();