Repository navigation
How to figure out if running on http vs https? #21488
Answered
by
suyundukov
marcofranssen
asked this question in
Help
|
In my api page I'm doing the following: export default function handler(req, res) {
const host = req.headers.host;
const proto = req.connection.encrypted ? "https" : "http";
//construct url for xml sitemaps
}However when deploying this code on vercel it seems the request is never encrypted. What would be a Vercel compatible way of checking the protocol? |
Answered by
suyundukov
Jan 24, 2021
Replies: 2 comments 2 replies
|
Hey, @marcofranssen. You can check const proto = req.headers['x-forwarded-proto']; |
2 replies
Answer selected by
marcofranssen
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Hey, @marcofranssen. You can check
X-Forwarded-Protoheader. As Vercel runs your app behind proxy server like Nginx, it's the only way to get request protocol: