javascript - Meteor routing issue: Webhook returning HTML page -


i working on meteor application must able listen post requests external api. so, trying implement webhook api can send data later stored in collection.

however, having trouble configuring route , posting basic header , message.

my code (in /lib/routes.js):

if(meteor.isclient){ router.route('/webhook', function(){          var request = this.request;          console.log("hook called");         console.log("headers: ", request.headers);         console.log("data: ", request.body);          this.response.writehead(200, {'content-type': 'text/html'});         this.response.write("you wrote: " + request.body);         this.response.write("\n");          this.response.end('success!\n');     }, {where: 'server'}); } 

my request :

curl -h "content-type: application/json" -d '{"message":"foo"}' http://localhost:3000/webhook 

the response in console huge html page has nothing request...

any ideas made mistake?

thanks in advance !

greg

note:if remove if(meteor.isclient){...} part, :

error: meteor.userid can invoked in method calls. use this.userid in publish functions.

by adding {where: 'server'} option route config, you're telling iron router server side route. means route accessible on server. wrapping route definition in meteor.isclient check means route defined when running client side (e.g. within users browser). can't define server side route on client side, remove meteor.isclient check.

with regards meteor.userid error you're getting when removing meteor.isclient check, 2 not related (since you're not referencing meteor.userid anywhere in sample posted). disable other parts of router config , test webhook itself; work expected (after removing meteor.isclient).


Comments