I am building a Meteor app that needs to be able access request data and take action accordingly. My goal is to be able to get GET/POST data on both the server side and the client side. This is what I have so far:
The code I have above works on the server, but not on the client. Any suggestions? Thanks!
Update for clarity (9/5/13)
If I start up my Meteor app, open the browser at http://localhost:3000/?foo=bar
, I want to be able to access foo
on the server AND on the client using the same API.
if (Meteor.isServer) {
var foo = RequestData.get('foo');
console.log(foo);
}
if (Meteor.isClient) {
var foo = RequestData.get('foo');
console.log(foo);
}
Does anyone have any ideas how I can accomplish this, whether it's modifying the code I already have, or starting over? Thanks!
Update on progress (9/5/13)
Thanks to @Denis for suggesting I use window.location.search
to read GET data on the client. I took this SO answer and adopted it to fit my needs for this Meteor package. The request-data.js
file posted above has been updated.
Now if I can just find a clean way to get the POST data to be available on the client. Thanks for the suggestions!