3 ms·
CORS has been no shortage of greys in my beard! When I'm writing some frontend that is hosted on localhost, with an API that is hosted on its domain somewhere,
by thepasswordis 5y ago
CORS has been no shortage of greys in my beard!
When I'm writing some frontend that is hosted on localhost, with an API that is hosted on its domain somewhere, it always is some sort of PITA to get the dev environ started.
There's a plugin for firefox that ignores CORS which is helpful for this. It's becoming less useful for me as my APIs now usually have a toggle to add a cross origin header which allows localhost. Still useful.
- dspillett 5y ago> writing some frontend that is hosted on localhost I assume this would also work for CORS purposes: for some time I've not used localhost where possible, for SSL reasons. Giving the local machine a perfectly valid name that I can get a cert for via LE (or already have a cert for, I actually use a non-production name for which I maintain a wildcard cert) is slightly less faf than having my own signing cert installed as trusted everywhere I might need it. Anything I might do publicly is HTTPS-only so my dev/test environments are too.
- eurasiantiger 5y agoJust use http-proxy to set up a local domain so you can access your dev environment at frontend.yoursite.local (proxied to localhost:3000) and the api at api.yoursite.local (proxied to whatever 3rd party api). Boom, problem solved. You can even rewrite headers and content of the requests in and out.
- jnovacho 5y agoDo you have any recomendations, which proxy to use? Specifically on Win.
- eurasiantiger 5y agohttps://www.npmjs.com/package/http-proxy https://www.npmjs.com/package/http-proxy Integrates nicely with existing JS frontend tooling.