Rest API CORS config env.properties
-
I have been struggling to query the rest API from anywhere other than localhost. I think this is due to the CORS setup (or lack thereof) in the env.properties file.
Does someone have an example of a CORS setup to allow me to query the rest API from a non-local-host machine? The only one I can find quoted on the forum has been removed/linked to a different page - so any help would be greatly appreciated
-
@MaP ensure forwarding headers are enabled in the mango properties. Also probably worth having localhost also assigned to your network ip in your hosts file.
Alternatively, leverage nginx as a reverse proxy to handle all external connections and treat them as if they are coming from localhost. Forwarding headers will also need to be enabled in mango.propertiesFox
-
I attempted the following but it still does not seem to have worked
rest.cors.enabled=true
rest.cors.allowedOrigins=*,localhost,<IP-HERE>
rest.cors.allowedMethods=PUT,POST,GET,OPTIONS,DELETE
rest.cors.allowedHeaders=LOGOUT,PASSWORD,content-type,accept,x-requested-with,authorization
rest.cors.exposedHeaders=
rest.cors.allowCredentials=true
rest.cors.maxAge=3600ahh using Nginx would be a clever trick, I would prefer not to do this on the production environment but this is a great tip for future installs, nginx with certbot would be handy
-
@MaP Did you get any further? Do note I've written a tutorial on here how to configure Nginx for a reverse proxy if needed
Fox
-
@MattFox I was able to run a test on a Mango4 unit and get access to rest V3 API via a non-local-host IP, but not on mango 3.7.2 REST V1 - this still only allows local-host originating requests. Wondering if there is something with IP tables or some network wizardry on the Mango itself to Destination NAT or masquarade requests from another port to overcome the CORS rules.
I would prefer a solution without involving another device/cloud server and a public IP address/Domain
-
@MaP Understandable, that's why I went with the reverse proxy route, using ip tables is too low level in the OSI for the CORS related issues in the application layer.
You may be able to set the env.properties to set the ip address of the interface you're trying to access to force it to only listen on that host ip address. See if that bears any fruit...Fox