Reputation: 823
I have a node.js app running on a server behind a nginx reverse proxy. Nginx is setup to handle both HTTP and HTTPS and forward both to the same node.js app. Is it possible for the node.js app to figure out if the request came from http or https?
Also, is it possible for the JS on the client side to figure out if its on http or https?
EDIT: found one solution for client side:
if (window.location.protocol != "https:")
is there a better way than this?
Upvotes: 0
Views: 63
Reputation: 14374
Just add custom header from nginx to node Usually it's
proxy_set_header X-Forwarded-Proto $scheme;
and in node it will appear in request.headers['x-forwarded-proto']
.
References:
Upvotes: 3