私は外部APIからのPOST要求を聞くことができる必要があるMeteorアプリケーションを開発中です。これを行うために、APIが後でコレクションに格納されるデータを送信できるWebhookを実装しようとしています。Meteorルーティングの問題:WebhookがHTMLページを返す
ただし、ルートの設定や基本的なヘッダーとメッセージの送信に問題があります。 (/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'});
}
マイリクエスト:
curl -H "Content-Type: application/json" -d '{"message":"foo"}' http://localhost:3000/webhook
私はコンソールで取得応答は何もない巨大なHTMLページですその要求に応じて...
私は間違いをどこにしたのか?
ご協力いただきありがとうございます。
グレッグ
注:私はif(Meteor.isClient){...}
一部を削除した場合、私が手:
Error: Meteor.userId can only be invoked in method calls. Use this.userId in publish functions.
Meteor.isClientチェックを削除しても、エラーが発生しました。あなたが言ったように、私はこの道を守っていただけではうまくいくでしょう! !Meteor.isServerチェックを私のルーターに持っていたすべてのMeteor.userId()呼び出しに追加して、ルータ全体を修正しました。これは完璧に機能しました!あなたの洞察をお寄せいただきありがとうございます。 – Greg