PageRenderTime 68ms CodeModel.GetById 39ms RepoModel.GetById 1ms app.codeStats 0ms

/config/sockets.js

https://gitlab.com/n4utilius/formas
JavaScript | 135 lines | 2 code | 20 blank | 113 comment | 0 complexity | db0c103c8324597b9b9896257a9b6fbb MD5 | raw file
  1. /**
  2. * WebSocket Server Settings
  3. * (sails.config.sockets)
  4. *
  5. * These settings provide transparent access to the options for Sails'
  6. * encapsulated WebSocket server, as well as some additional Sails-specific
  7. * configuration layered on top.
  8. *
  9. * For more information on sockets configuration, including advanced config options, see:
  10. * http://sailsjs.org/#/documentation/reference/sails.config/sails.config.sockets.html
  11. */
  12. module.exports.sockets = {
  13. /***************************************************************************
  14. * *
  15. * Node.js (and consequently Sails.js) apps scale horizontally. It's a *
  16. * powerful, efficient approach, but it involves a tiny bit of planning. At *
  17. * scale, you'll want to be able to copy your app onto multiple Sails.js *
  18. * servers and throw them behind a load balancer. *
  19. * *
  20. * One of the big challenges of scaling an application is that these sorts *
  21. * of clustered deployments cannot share memory, since they are on *
  22. * physically different machines. On top of that, there is no guarantee *
  23. * that a user will "stick" with the same server between requests (whether *
  24. * HTTP or sockets), since the load balancer will route each request to the *
  25. * Sails server with the most available resources. However that means that *
  26. * all room/pubsub/socket processing and shared memory has to be offloaded *
  27. * to a shared, remote messaging queue (usually Redis) *
  28. * *
  29. * Luckily, Socket.io (and consequently Sails.js) apps support Redis for *
  30. * sockets by default. To enable a remote redis pubsub server, uncomment *
  31. * the config below. *
  32. * *
  33. * Worth mentioning is that, if `adapter` config is `redis`, but host/port *
  34. * is left unset, Sails will try to connect to redis running on localhost *
  35. * via port 6379 *
  36. * *
  37. ***************************************************************************/
  38. // adapter: 'memory',
  39. //
  40. // -OR-
  41. //
  42. // adapter: 'redis',
  43. // host: '127.0.0.1',
  44. // port: 6379,
  45. // db: 'sails',
  46. // pass: '<redis auth password>'
  47. /***************************************************************************
  48. * *
  49. * Whether to expose a 'get /__getcookie' route with CORS support that sets *
  50. * a cookie (this is used by the sails.io.js socket client to get access to *
  51. * a 3rd party cookie and to enable sessions). *
  52. * *
  53. * Warning: Currently in this scenario, CORS settings apply to interpreted *
  54. * requests sent via a socket.io connection that used this cookie to *
  55. * connect, even for non-browser clients! (e.g. iOS apps, toasters, node.js *
  56. * unit tests) *
  57. * *
  58. ***************************************************************************/
  59. // grant3rdPartyCookie: true,
  60. /***************************************************************************
  61. * *
  62. * `beforeConnect` *
  63. * *
  64. * This custom beforeConnect function will be run each time BEFORE a new *
  65. * socket is allowed to connect, when the initial socket.io handshake is *
  66. * performed with the server. *
  67. * *
  68. * By default, when a socket tries to connect, Sails allows it, every time. *
  69. * (much in the same way any HTTP request is allowed to reach your routes. *
  70. * If no valid cookie was sent, a temporary session will be created for the *
  71. * connecting socket. *
  72. * *
  73. * If the cookie sent as part of the connetion request doesn't match any *
  74. * known user session, a new user session is created for it. *
  75. * *
  76. * In most cases, the user would already have a cookie since they loaded *
  77. * the socket.io client and the initial HTML pageyou're building. *
  78. * *
  79. * However, in the case of cross-domain requests, it is possible to receive *
  80. * a connection upgrade request WITHOUT A COOKIE (for certain transports) *
  81. * In this case, there is no way to keep track of the requesting user *
  82. * between requests, since there is no identifying information to link *
  83. * him/her with a session. The sails.io.js client solves this by connecting *
  84. * to a CORS/jsonp endpoint first to get a 3rd party cookie(fortunately this*
  85. * works, even in Safari), then opening the connection. *
  86. * *
  87. * You can also pass along a ?cookie query parameter to the upgrade url, *
  88. * which Sails will use in the absense of a proper cookie e.g. (when *
  89. * connecting from the client): *
  90. * io.sails.connect('http://localhost:1337?cookie=smokeybear') *
  91. * *
  92. * Finally note that the user's cookie is NOT (and will never be) accessible*
  93. * from client-side javascript. Using HTTP-only cookies is crucial for your *
  94. * app's security. *
  95. * *
  96. ***************************************************************************/
  97. // beforeConnect: function(handshake, cb) {
  98. // // `true` allows the connection
  99. // return cb(null, true);
  100. //
  101. // // (`false` would reject the connection)
  102. // },
  103. /***************************************************************************
  104. * *
  105. * This custom afterDisconnect function will be run each time a socket *
  106. * disconnects *
  107. * *
  108. ***************************************************************************/
  109. // afterDisconnect: function(session, socket, cb) {
  110. // // By default: do nothing.
  111. // return cb();
  112. // },
  113. // More configuration options for Sails+Socket.io:
  114. // http://sailsjs.org/#/documentation/reference/sails.config/sails.config.sockets.html
  115. };