API to use the generated certificates
onerinas opened this issue · 7 comments
How would you like to expand the functionalities?
Ability to generate and use certs directly for the existing server
Are there alternatives?
- Alternative is to use express app included in htttps-localhost but it cannot be used in cases like socket since app.listen won't work.
https://socket.io/docs/#Using-with-Express - Another alternative is to use mkcert directly to generate the cert. This is an extra step to download the certs whereas https-localhost does that automatically and developer doesn't have to run commands for that
Is it a breaking change?
Probably yes, depending upon what would be resulting API when this feature is implemented
Hi @onerinas!
Take a look to the getCerts()
functions. I could try to make it available programmatically.
Then you can start the server with https.createServer(await getCerts(), app).listen(port)
Otherwise, we can add a parameter to the createServer()
or the listen()
functions to pas the app
, but I'm not sure that cover all the possibilities. Probably a lambda would be better but at this point providing getCerts()
would be more or less the same.
PS: I will be on a trip next week, don't throw in the towel if you don't hear me, I'll be back next weekend and I'll read all the messages ;)
No problem at all, enjoy your trip and thank you for the quick response!
Then you can start the server with https.createServer(await getCerts(), app).listen(port)
Yes, I was hoping for something like that.
Fine, next weekend I'll try to rearrange the structure to expose getCerts()
👌
I've forked the repo to use in our project. Here is the commit: onerinas@ae6386e
usage:
https.createServer(await httpsLocalhost.getCerts(), app)
I don't have any tests to create a PR here.
Hi @onerinas,
I checked your PR #22 but contains breaking changes.
In particular, it changes the current use from
const httpsLocalhost = require("https-localhost")
const app = httpsLocalhost()
to
const httpsLocalhost = require("https-localhost").app
const app = httpsLocalhost()
Actually, I won't push a breaking change now. Maybe in the future, but I will totally remove express in that case.
I've created a branch that should solve your problem.
I paste an example for clarity:
const httpsLocalhost = require("https-localhost")()
// const app = ...
// const port = 443
const certs = await httpsLocalhost.getCerts()
const server = https.createServer(certs, app).listen(port)
Let me know if this solution can work for you.
Yes, this would work!
Fine!
I'll publish it in the next few days together with other changes.