{"action":"created","issue":{"url":"https://api.github.com/repos/Daplie/letsencrypt-express/issues/15","repository_url":"https://api.github.com/repos/Daplie/letsencrypt-express","labels_url":"https://api.github.com/repos/Daplie/letsencrypt-express/issues/15/labels{/name}","comments_url":"https://api.github.com/repos/Daplie/letsencrypt-express/issues/15/comments","events_url":"https://api.github.com/repos/Daplie/letsencrypt-express/issues/15/events","html_url":"https://github.com/Daplie/letsencrypt-express/issues/15","id":132898547,"number":15,"title":"Socket.io+LEX","user":{"login":"mdcsfk","id":12139447,"avatar_url":"https://avatars.githubusercontent.com/u/12139447?v=3","gravatar_id":"","url":"https://api.github.com/users/mdcsfk","html_url":"https://github.com/mdcsfk","followers_url":"https://api.github.com/users/mdcsfk/followers","following_url":"https://api.github.com/users/mdcsfk/following{/other_user}","gists_url":"https://api.github.com/users/mdcsfk/gists{/gist_id}","starred_url":"https://api.github.com/users/mdcsfk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdcsfk/subscriptions","organizations_url":"https://api.github.com/users/mdcsfk/orgs","repos_url":"https://api.github.com/users/mdcsfk/repos","events_url":"https://api.github.com/users/mdcsfk/events{/privacy}","received_events_url":"https://api.github.com/users/mdcsfk/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-02-11T06:11:36Z","updated_at":"2016-02-15T19:59:35Z","closed_at":"2016-02-15T16:10:40Z","body":"Hi\r\nI don't get, how do i configure LEX with socket.io. Here what I have now:\r\n\r\nserver.js\r\n```\r\n\r\nvar express    = require('express');\r\nvar app = express();\r\nvar bodyParser = require('body-parser');\r\n\r\napp.use(bodyParser.urlencoded({limit: '50mb', extended: true }));\r\napp.use(bodyParser.json({limit: '50mb'}));\r\n\r\nvar port = 80;\r\nif(process.argv[2] == 'dev') port = 3001;\r\n\r\nvar router = express.Router();\r\n\r\napp.use(function (req, res, next) {\r\n    res.setHeader('Access-Control-Allow-Origin', '*');\r\n    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');\r\n    res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type, userId');\r\n    next();\r\n});\r\n\r\nvar api = require('./api');\r\napi(app, port)\r\n\r\napp.use(express.static(__dirname + \"/../dist\"));\r\napp.get('/', function(req, res) {\r\n  res.render('index.html');\r\n});\r\nconsole.log('Magic happens on port ' + port);\r\n```\r\n\r\napi.js\r\n```\r\nvar API = function(app, port){\r\n  var pg = require('pg');\r\n  var lex = require('letsencrypt-express').testing();\r\n\r\n  var connectedUsers = {};\r\n\r\n  var config ={\r\n    user: \"postgres\",\r\n    password: \"password\",\r\n    database: \"production\",\r\n    port: 5432,\r\n    host: \"serverIpAddress\",\r\n    ssl: false\r\n  }; \r\n\r\n  pg.connect(config, function(err, client, done) {\r\n\r\n    if (err) {\r\n      return console.error('error fetching client from pool', err);\r\n    }\r\n    // var server = require('http').Server(app);\r\n    var server = lex.create({\r\n      configDir: './letsencrypt.config',\r\n      onRequest: app,\r\n      letsencrypt: null,\r\n    });\r\n\r\n\r\n    var io = require('socket.io')(server);\r\n\r\n    server.listen(port);\r\n\r\n    io.on('connection', function (socket) {\r\n      console.log('new connection')\r\n      \r\n    });\r\n  });\r\n\r\n}\r\n\r\nmodule.exports = API\r\n```\r\n\r\ntake a look at commented out line in api.js: everything works fine when I use this instead of:\r\n```\r\nvar server = lex.create({\r\n      configDir: './letsencrypt.config',\r\n      onRequest: app,\r\n      letsencrypt: null,\r\n    });\r\n```\r\nWith LEX i'm receiving this error trying to run the server:\r\n\r\n```\r\n[LEX] testing mode turned on\r\n[LEX] default server: https://acme-staging.api.letsencrypt.org/directory\r\n\r\n\r\n###################################################\r\n#                                                 #\r\n#     Open up a browser and visit this server     #\r\n#     at its domain name.                         #\r\n#                                                 #\r\n#                                 ENJOY!          #\r\n#                                                 #\r\n###################################################\r\n\r\n\r\nNote: testing certs will be installed because .testing() was called.\r\n      remove .testing() to get live certs.\r\n\r\n\r\n[LEX] automatic registration handling turned on for testing.\r\n\r\n\r\nMagic happens on port 3001\r\n[LEX] creating sniCallback {\r\n  \"configDir\": \"./letsencrypt.config\",\r\n  \"onRequest\": {\r\n    \"domain\": null,\r\n    \"_events\": {},\r\n    \"_eventsCount\": 3,\r\n    \"_connections\": 0,\r\n    \"_handle\": null,\r\n    \"_usingSlaves\": false,\r\n    \"_slaves\": [],\r\n    \"_unref\": false,\r\n    \"allowHalfOpen\": true,\r\n    \"pauseOnConnect\": false,\r\n    \"httpAllowHalfOpen\": false,\r\n    \"timeout\": 120000\r\n  },\r\n  \"letsencrypt\": {\r\n    \"backend\": {}\r\n  },\r\n  \"debug\": true,\r\n  \"webrootPath\": \"/var/folders/2m/vfw1bgqd4pv7hk86kcbvcrlc0000gn/T/acme-challenge\",\r\n  \"privkeyPath\": \"./letsencrypt.config/live/:hostname/privkey.pem\",\r\n  \"fullchainPath\": \"./letsencrypt.config/live/:hostname/fullchain.pem\",\r\n  \"certPath\": \"./letsencrypt.config/live/:hostname/cert.pem\",\r\n  \"chainPath\": \"./letsencrypt.config/live/:hostname/chain.pem\",\r\n  \"server\": \"https://acme-staging.api.letsencrypt.org/directory\"\r\n}\r\nprojectRootFolder/node_modules/socket.io/node_modules/engine.io/lib/server.js:358\r\n  var listeners = server.listeners('request').slice(0);\r\n                         ^\r\n\r\nTypeError: server.listeners is not a function\r\n    at Server.attach (projectRootFolder/node_modules/socket.io/node_modules/engine.io/lib/server.js:358:26)\r\n    at Function.attach (projectRootFolder/node_modules/socket.io/node_modules/engine.io/lib/engine.io.js:124:10)\r\n    at Server.listen.Server.attach (projectRootFolder/node_modules/socket.io/lib/index.js:226:21)\r\n    at new Server (projectRootFolder/node_modules/socket.io/lib/index.js:51:17)\r\n    at Server (projectRootFolder/node_modules/socket.io/lib/index.js:39:41)\r\n    at projectRootFolder/server/api.js:73:34\r\n    at projectRootFolder/node_modules/pg/lib/pool.js:82:9\r\n    at projectRootFolder/node_modules/pg/node_modules/generic-pool/lib/generic-pool.js:281:11\r\n    at projectRootFolder/node_modules/pg/lib/pool.js:56:18\r\n    at null.<anonymous> (projectRootFolder/node_modules/pg/lib/client.js:149:7)\r\n    at g (events.js:260:16)\r\n    at emitOne (events.js:82:20)\r\n    at emit (events.js:169:7)\r\n    at Socket.<anonymous> (projectRootFolder/node_modules/pg/lib/connection.js:109:12)\r\n    at emitOne (events.js:77:13)\r\n    at Socket.emit (events.js:169:7)\r\n```\r\nI guess, I have very simple mistake in my code, because I was not configuring Socket.io with SSL before.\r\n\r\nThank you"},"comment":{"url":"https://api.github.com/repos/Daplie/letsencrypt-express/issues/comments/184364389","html_url":"https://github.com/Daplie/letsencrypt-express/issues/15#issuecomment-184364389","issue_url":"https://api.github.com/repos/Daplie/letsencrypt-express/issues/15","id":184364389,"user":{"login":"Beclin","id":17239283,"avatar_url":"https://avatars.githubusercontent.com/u/17239283?v=3","gravatar_id":"","url":"https://api.github.com/users/Beclin","html_url":"https://github.com/Beclin","followers_url":"https://api.github.com/users/Beclin/followers","following_url":"https://api.github.com/users/Beclin/following{/other_user}","gists_url":"https://api.github.com/users/Beclin/gists{/gist_id}","starred_url":"https://api.github.com/users/Beclin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Beclin/subscriptions","organizations_url":"https://api.github.com/users/Beclin/orgs","repos_url":"https://api.github.com/users/Beclin/repos","events_url":"https://api.github.com/users/Beclin/events{/privacy}","received_events_url":"https://api.github.com/users/Beclin/received_events","type":"User","site_admin":false},"created_at":"2016-02-15T19:59:35Z","updated_at":"2016-02-15T19:59:35Z","body":"Thanks for your help. Now it works.\r\n\r\napp.js\r\n```\r\nvar express = require('express');\r\nvar app = express();\r\nvar socketIO = require('socket.io');\r\nvar LEX = require('letsencrypt-express').testing();\r\nvar https = require('http2');\r\n\r\napp.get('/', function (req, res) {\r\n  res.sendFile(__dirname + '/index.html');\r\n});\r\n\r\nvar lex = LEX.create({\r\n  configDir: '/etc/letsencrypt'\r\n, letsencrypt: null\r\n, approveRegistration: function (hostname, cb) {\r\n    cb(null, {\r\n      domains: ['example.com']\r\n    , email: 'info@example.com'\r\n    , agreeTos: true\r\n    });\r\n  }\r\n});\r\n\r\nvar server = https.createServer(lex.httpsOptions, LEX.createAcmeResponder(lex, app));\r\nserver.listen(443);\r\n  \r\nvar io = socketIO.listen(server);\r\nio.on('connection', function (socket) {\r\n  socket.emit('news', { hello: 'world' });\r\n  socket.on('my other event', function (data) {\r\n    console.log(data);\r\n  });\r\n});\r\n```\r\n\r\nindex.html\r\n```\r\n<script src=\"https://cdn.socket.io/socket.io-1.4.5.js\"></script>\r\n<script>\r\n  var socket = io.connect('https://example.com');\r\n  socket.on('news', function (data) {\r\n    console.log(data);\r\n    socket.emit('my other event', { my: 'data' });\r\n  });\r\n</script>\r\n```"}}