Redirect http to https express.js

前端 未结 6 1993
-上瘾入骨i
-上瘾入骨i 2020-12-19 16:56

I\'m trying to reroute http (80) to https (443) in my express app. I\'m using some middle ware to do this. If i go to my https://my-example-

6条回答
  •  遥遥无期
    2020-12-19 17:15

    You can achieve redirection from http to https

    if(req.headers["x-forwarded-proto"] == "http") {
     res.redirect(301, "https://" + req.host+req.url);
                    next();
    }
    

提交回复
热议问题