Parse, NodeJS and CORS
A beautiful trio.
One of the issues with the projects that I have is the need to develop API’s that will be consumed by either mobile apps or web apps, served by a particular domain. Because of SOP (Single Origin Policy), this means I need to have a way to get around it. CORS (Cross-Origin Resource Sharing) is the answer. For those who are new to CORS, there’s this excellent website about it. Fortunately there’s this library for expressjs. Parse.com does not have CORS out of the box. Either you have to add the needed routing rules with the right headers to support it, or you can just download the library that does just that for you.
Let me take you step by step.
- Make sure you have parse installed. Just copy the command from here.
curl -s https://www.parse.com/downloads/cloud_code/installer.sh | sudo /bin/bash
2. Get the CORS library at
4. Change the path on vary.js
5. Add these two lines where instantiated your expressjs app.
And voila. You have CORS. Happy coding.