Created
January 10, 2017 06:00
-
-
Save kfatehi/2372b6b0bff92d07a69a0fc737463f04 to your computer and use it in GitHub Desktop.
notes on adding tls to matrix appservice bridge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tracing from matrix-appservice-imessage on down through the turtle stack: | |
The call bridge.run(port, config) makes the server listen: | |
https://github.com/kfatehi/matrix-appservice-imessage/blob/master/index.js#L181 | |
bridge.run, as defined in matrix-appservice-bridge, calls `appService.listen(port)`: | |
https://github.com/matrix-org/matrix-appservice-bridge/blob/master/lib/bridge.js#L253 | |
`AppService` is defined in matrix-appservice-node and calls `app.listen(port, ...)`: | |
https://github.com/matrix-org/matrix-appservice-node/blob/master/lib/app-service.js#L184 | |
`app` is an express instance: | |
https://github.com/matrix-org/matrix-appservice-node/blob/master/lib/app-service.js#L21 | |
When you just run `app.listen` express uses `require('http')` under the hood. In order to use tls, you need to do the following: | |
``` | |
var fs = require('fs'); | |
var https = require('https'); | |
var app = require('express')(); // XXX you have this already | |
var options = { | |
key : fs.readFileSync('server.key'), | |
cert : fs.readFileSync('server.crt') | |
}; | |
https.createServer(options, app).listen(3000, function () { | |
console.log('Started!'); | |
}); | |
``` | |
The only thing that's curious is the number of arguments being passed into the express `listen` method, and how that would translate over to this. | |
According to the docs | |
https://expressjs.com/en/api.html#app.listen | |
> This method is identical to Node’s http.Server.listen(). | |
For more on that you can look at | |
https://nodejs.org/api/https.html#https_class_https_server |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment