[SOLVED] ERR_SSL_PROTOCOL_ERROR on https://localhost:3000 | SoloLearn: Learn to code for FREE!

+3

[SOLVED] ERR_SSL_PROTOCOL_ERROR on https://localhost:3000

I was trying to enforce HTTPS on my deployed website on Heroku. https://help.heroku.com/J2R1S4T8/can-heroku-force-an-application-to-use-ssl-tls After setting up npm module express-sslify, I succeeded in forcing to use HTTPS on my deployed site on Heroku with 301 redirection; https://www.npmjs.com/package/express-sslify but then when I test the app in my computer with node server.js it forces my localhost to redirect to https://localhost:3000 and Chrome shows the above error ERR_SSL_PROTOCOL_ERROR I have edited the middleware line to if (app.get("env") === "production") { app.use(enforce.HTTPS({ trustProtoHeader: true })); } following issue #22: https://github.com/florianheinemann/express-sslify/issues/22 but it kinds of remember it I have queryed in chrome://net-internals/#hsts and localhost is not in the list. Both of above steps does not solve the problem. Can't develop any app now 🤷‍♂️ What should I do? Use OpenSSL to self-sign a SSL cert? But how to use that for development only?

5/25/2020 3:22:14 PM

Gordon

11 Answers

New Answer

+2

Gordon clear your browser cache or use private browsing.

+4

I normally use reverse proxy, NGINX to redirect http to https port on production server, so i have no url redirection on node express.js side.

+3

does it works on heroku ? i see the express-sslify module, looks like its just enforce the route to use https. so you'll still need to setup https server yourself

+3

Calviղ I watched a tutorial about using NGINX on DigitalOcean last night. I don't know how to do that with Heroku. https://youtu.be/oykl1Ih9pMg And now Chrome kinds of remember that localhost should be redirected to https. Because when I first node server.js I have not had the if (app. get('env') part

+3

Calviղ Thanks for your suggestion, let me try tonight

+2

Gordon How do you npm start? node app.js? If you put console.log(app.get("env")) what do you get?

+2

Calviղ I use node server.js to launch the app at localhost When I console.log(app.get('env')) in my computer, I get development

+2

If env is not "production", then it shouldn't have run enforce.HTTPS? 🤔

+2

Calviղ After clearing cache, problem is solved, thanks.

+1

Taste Yes it works on Heroku learntogether-hk.com gordonchan.app Both domain will be redirected to https now. What I have done is this : https://youtu.be/VEJEGV11NEw It worked on Heroku because I have both purchased SSL certificates at namecheap/GoDaddy and the ACM at Heroku. It doesn't work on localhost because I don't have SSL certificate at localhost. Even if I put the app.use(enforce...) in if env, it still redirect me to https on localhost...

+1

Well done 👍 Gordon