Ask coding questions

← Back to all posts
how should i force https
Koalaknightmi (1)

in a node.js project with a html webpage what is the best way to force a incoming http request to https

Answered by mat1 (2497) [earned 5 cycles]
View Answer
Commentshotnewtop
mat1 (2497)

You can add this small code snippet to your html to convert http to https:

<script>if(location.protocol!=="https:"){location.protocol="https:"}</script>

Please mark my comment as the answer if it answered your question. Thanks!