Node.js express app.get and app.post

I am working with a facebook application canvas that requires a message. I use express to handle app.post ('/') and app.get ('/') .. is it possible to combine them into one function? Thanks

+8
facebook express
source share
2 answers

Besides binding the same function to POST and GET , as suggested by JustSid, in another answer you can use app.all('/', handler) to route all types of requests for work.

+26
source share

You can have one function for processing both messages and receiving:

 function sharedHandler(req, res) { // Some custom logic here } app.get('/', sharedHandler); app.post('/', sharedHandler); 
+7
source share

All Articles