Tuesday, March 4, 2014

POST to Angular.JS by Facebook Canvas App

I was writing a Facebook Canvas App with Flask. Then I decided to move my frontend to AngularJS. I wanted to put the AngularJS static code to a static hosting provider to avoid higher costs. Nevertheless, I realized that I had forgotten that I can't handle POST requests by AngularJS since it doesn't have a dynamic server.

Facebook Canvas performs a POST request with signed_request parameter to your homepage and you should handle that parameter to see who the logged user is.

What I did was: create a Node.JS app with express.js framework. Convert homepage to view, add a hidden input field in the HTML code and handle POST parameter by Node.JS, filling that hidden input.

When I did this, facebook posted the signed_request parameter and I placed that code into the hidden field. Now AngularJS code can post that signed_request code to the backend API server to process it or use it client-side.

No comments: