question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to create https server and support wss use koa2? I need it very much.

See original GitHub issue

http + https =

const Koa = require('koa');
const app = new Koa();
http.createServer(app.callback()).listen(80);
const options = {
    key: fs.readFileSync('./ssl/private.pem', 'utf8'),
    cert: fs.readFileSync('./ssl/20180303.crt', 'utf8')
};
https.createServer(options, app.callback()).listen(443);

http + ws =

const Koa = require('koa');
const websockify = require('koa-websocket');
const app = websockify(new Koa());
app.listen(80);

https + wss = ?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:18
  • Comments:5

github_iconTop GitHub Comments

5reactions
saurabh-codewordcommented, Dec 30, 2019

you can do it this way:

const server = new Koa();

// ... middlewares and routes

const options = {
   // Local certificates, if you don;t have them generate from mkcert or letsEncrypt
    key: fs.readFileSync("localhost-key.pem"),
    cert: fs.readFileSync("localhost.pem")
  };

  https.createServer(options, server.callback()).listen(port);
2reactions
motet-acommented, Apr 30, 2017

In anyway, you can perfectly stick with HTTP on the Koa side and use a reverse-proxy (nginx, httpd) to enable HTTPS — I think most people use Koa this way (at least I use Koa this way).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Implementing https: and wss: support in Express ... - Medium
And here we go, we have a https server! Try it from your browser or Postman. If you wish to switch back to...
Read more >
How to create an https server? - Node.js
To create an HTTPS server, you need two things: an SSL certificate, and built-in https Node.js module. We need to start out with...
Read more >
Koa 本地搭建HTTPS 环境 - 牛さんの部落格
... a self-signed certificate Node.js Documentation - HTTPS How to create https server and support wss use koa2? I need it very much....
Read more >
node.js - How to Create Secure(TLS/SSL) Websocket Server
Currently I'm running ws server. Now I want to secure this connection by using secure connections i.e by implementing wss protocol and also...
Read more >
Setup secure connections (TLS/WSS/HTTPS) with certificate
WSS — For WebSocket transport between Brekeke SIP Server and Browser. If you use webRTC feature, this secure connection is needed. HTTPS –...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found