By Laurence 🍕
This is version 2.0 of the JustEat app and a personal project. For a more comprehensive detailing of the front end build, it's challenges and further documentation please find it HERE.
In order to run APIs to our front-end for Project 2, we needed to adhere to HTTP standards of Cross-Origin Resource Sharing (CORS). It is common for an API to be configured in a way to deny direct browser requests (in the from of ‘Access-Control-Allow-Origin: originType’), this is where a backend and middleware become useful.
In order to subvert the CORS protocol our requests were routed though the CORS-Anywhere Heroku App. This was satisfactory for development and short-term use, unfortunately this caused other quality of life issues - 30 second load times, another point of failure, exposed API keys, and the potential for total failure if the CORS-Anywhere App changed or became unavailable.
Implementation was relatively simple - installing Express and initializing a back-end. Any requests that where being made on the front-end were routed to the back-end using the "/api" prefix. Simple controllers were set to send and respond for the APIs in use (in this case- postcodes.io, JustEatAPI and StaticGoogleMaps). Finally the front-end requests were re-configured to expect data in a new way - specifically the postcode API request ran to expect response codes.
Find it Here! --> Just Eat App V2 🍕