fork download
  1. var WebSocketServer = require('ws').Server;
  2. var https = require('https');
  3. var keepaliveagent = require('keep-alive-agent');
  4. var util = require('util');
  5. var PHPUnserialize = require('php-unserialize');
  6. var Promise = require('promise');
  7.  
  8. var global_websocket_server = new WebSocketServer({port: 8081});
  9.  
  10. function handle_chunks(request, callback)
  11. {
  12. var data = '';
  13.  
  14. request.on('data', function (chunk) {
  15. data += chunk;
  16. });
  17.  
  18. request.on('end', function () {
  19. callback(data);
  20. });
  21. }
  22.  
  23. var shopify_agent = new keepaliveagent.Secure();
  24.  
  25. var first_connection_options = {
  26. hostname: 'foo',
  27. port: 443,
  28. path: '/',
  29. method: 'HEAD',
  30. auth: 'foo',
  31. agent: shopify_agent
  32. };
  33.  
  34. https.get(first_connection_options, function (res) {
  35. console.log(res.statusCode);
  36. });
  37.  
  38. global_websocket_server.on('connection', function (websocket_client) {
  39. websocket_client.on('message', function (data, flags) {
  40. var options = {
  41. hostname: 'foo',
  42. port: 443,
  43. path: '/admin/products.json',
  44. auth: 'foo',
  45. agent: shopify_agent
  46. };
  47.  
  48. console.time('request');
  49. https.get(options, function (res) {
  50. handle_chunks(res, function (data) {
  51. console.timeEnd('request');
  52. console.log(data.length);
  53. /*websocket_client.send(data, function (e) {
  54.  
  55. if (e != undefined)
  56. console.log("sent", e);
  57. })*/
  58. });
  59. }).on('error', function (e) {
  60. console.log('erorr', e.message);
  61. });
  62.  
  63. console.log('message', data);
  64. });
  65. });
Runtime error #stdin #stdout #stderr 0.64s 381888KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
js: uncaught JavaScript runtime exception: ReferenceError: "require" is not defined.