Using Socket.io with Ltijs
See original GitHub issueAs I am currently using Ltijs for an app that uses sockets, specifically Socket.io, I would need to access the server
object. for example, var server = app.listen(4000, ...
so that I can create a socket, var io = socketIO(server)
. I have looked at the source code for ltijs, and in the Server.js file, I see that for the listen
function,
listen (port) {
return new Promise((resolve, reject) => {
if (this.ssl) {
this.server = https.createServer(this.ssl, this.app).listen(port)
} else {
this.server = this.app.listen(port)
}
this.server.on('listening', () => {
resolve(true)
})
this.server.on('error', (err) => {
reject(err)
})
})
}
the server
object is being assigned as a class variable called server
In the Provider.js file,
this.#server = new Server(options ? options.https : false, options ? options.ssl : false, this.#ENCRYPTIONKEY, options ? options.cors : true, options ? options.serverAddon : false)
/**
* @description Express server object.
*/
this.app = this.#server.app
only the app, as in app = express()
is exposed. However, I need access to the server
object so ideally, this.server = this.#server.server
so that I can run Socket.io within the same HTTP server instance, var io = socketIO(server)
. Thank you for looking into this. Heres a resource link that explains more: https://stackoverflow.com/questions/17696801/express-js-app-listen-vs-server-listen
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
Ok thanks for the tip. I’ll probably need to look into this more. I’ll update again when things become clearer thanks again.
Update: I was using
app.use(cookieParser());
in my app without passing a secret to it. Changed it toapp.use(cookieParser(options.moodle.LTI_KEY));
, aka passed the LTI_KEY into cookieParser(), and it works now. Thanks so much for this @CvmcostaProbably, are you passing a secret to cookieParser? I believe that for consistency you should pass the LTI_KEY to it.