You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have our parse server behind a reverse proxy (nginx) to deal with https, and a non-standard port. So when you hit https://some.company.com:12345/parse/ nginx redirects it to http://127.0.0.1:1337/parse on the local server. Currently, if a file should be fetched per request from parse server the middleware.js uses
Because we have this behind a proxy we have used app.enable('trust proxy') in our express server that uses parse-server as sub application. This setting will be forwarded to the parse-serve app (See http://expressjs.com/en/4x/api.html#app.settings.table) so that req.protocol equals https and not http as it would without. Therefore we have X-Forwarded-Proto set to $scheme in nginx, that evaluates to https.
So this is fine.
But: req.get('host') reads directly the Host: field in the HTTP request and ignores that we are behind a proxy. Express states that using req.hostname will use the X-Forwarded-Host instead if app.enabled('trust proxy') === true (See http://expressjs.com/en/4x/api.html#req.hostname )
Therefore we changed the req.get('host') to req.hostname.
This still doesn't take care of the port. For this we added the following lines to middleware.js and configured nginx to send the correct port via X-Forwarded-Port:
varforwarded_port=req.get('X-Forwarded-Port');varport=forwarded_port ? ":"+forwarded_port : "";// if there's no forwarded port, don't add the port// adjust mountvarmount=req.protocol+'://'+req.hostname+port+mountPath;
This solution works for us, so that we get correct responses to get the file at https://somecompany.com:12345/parse/files/someapp/random_string_name.file
Our question is: Was this the correct part of the code to modify? If not, where should we change it then? Do you have any other suggestions? We would like to help and create an appropriate pull request if you would approve of this suggestions.
The text was updated successfully, but these errors were encountered:
Environment Setup
We have our parse server behind a reverse proxy (nginx) to deal with https, and a non-standard port. So when you hit https://some.company.com:12345/parse/ nginx redirects it to http://127.0.0.1:1337/parse on the local server. Currently, if a file should be fetched per request from parse server the
middleware.js
usesBecause we have this behind a proxy we have used
app.enable('trust proxy')
in our express server that uses parse-server as sub application. This setting will be forwarded to the parse-serve app (See http://expressjs.com/en/4x/api.html#app.settings.table) so thatreq.protocol
equalshttps
and nothttp
as it would without. Therefore we haveX-Forwarded-Proto
set to$scheme
in nginx, that evaluates tohttps
.So this is fine.
But:
req.get('host')
reads directly theHost:
field in the HTTP request and ignores that we are behind a proxy. Express states that usingreq.hostname
will use theX-Forwarded-Host
instead ifapp.enabled('trust proxy') === true
(See http://expressjs.com/en/4x/api.html#req.hostname )Therefore we changed the
req.get('host')
toreq.hostname
.This still doesn't take care of the port. For this we added the following lines to
middleware.js
and configured nginx to send the correct port viaX-Forwarded-Port
:This solution works for us, so that we get correct responses to get the file at
https://somecompany.com:12345/parse/files/someapp/random_string_name.file
Our question is: Was this the correct part of the code to modify? If not, where should we change it then? Do you have any other suggestions? We would like to help and create an appropriate pull request if you would approve of this suggestions.
The text was updated successfully, but these errors were encountered: