Skip to content
Advertisement

How Can I Transfer This http Node.Js to run on https?

Recently i created a node js and webrtc project that use http. But I notified that webrtc only works with https. So how can i transfer this http based node js file to https based one? Please help me.

Really i have no idea how to do this. So please help me to make it. What is need is to run this file over https. Not in http. As you can see, the below code use just http. As the webrtc need to run over https, i just need to make this file to run over https too

JavaScript

Advertisement

Answer

HTTPS requires a security certificate which matches the domain name. Both domain name and certificate for production usage can be purchased online and will have an expiration date and will need renewals.

The certificate comprises of two files cert.pem and key.pem.

For local development a self-signed untrusted certificate can be generated for localhost domain (via openssl command-line tool).

JavaScript

The original code can be updated from ‘http’ to ‘https’ and those two files need to be loaded and passed as options to https.createServer()

I also had to update the call to ‘node-static’ as it was not serving local files.

JavaScript

Starting the server and visiting https://localhost:4000 will be prompted with untrusted certificate warning which you have to acknowledge.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement