getting at client cookies server side

640 views
Skip to first unread message

Tim Heckel

unread,
Jan 13, 2013, 9:59:02 AM1/13/13
to meteo...@googlegroups.com
I have a requirement where I need to check if a client cookie exists that was set at a different domain...using javascript client side with document.cookie won't work for because what I get back is restricted to my current domain. I've seen this answer on SO and am posting this question as a follow-up. (I've also made a comment on that thread).

Ideally, there'd be a simple baked-in mechanism to do this. I'm going to look into the source a bit more. For the time being, what about this module?


And this creates the object in a node context -- the question is, how do we get a handle on the req object from within Meteor's server side code?
server = http.createServer( function( req, res ) {
  var cookies = new Cookies( req, res, keys )

Tim Heckel

unread,
Jan 13, 2013, 11:20:29 PM1/13/13
to meteo...@googlegroups.com
So I haven't found an answer yet, but I did discover the use of the connect middleware package per this SO answer. One of the modules included in the connect middleware is a cookieParser, and from my look at the accounts-oauth-helper/oauth_server.js file, this is what I've been able to piece together thus far:

 __meteor_bootstrap__.app
    .use(connect.cookieParser())
    .use(function(req, res, next) {
console.log("here?");
      Fiber(function () {
        console.log(JSON.stringify(req.cookies));
      }).run();
    });

I have this inside a regular isServer block, but it's not emitting anything to the console yet. Any thoughts?

Dror Matalon

unread,
Jan 13, 2013, 11:24:43 PM1/13/13
to meteo...@googlegroups.com
where are you getting the request and response objects from? If you
have the request object, getting the cookies should be easy, but I
don't know that Meteor provides that.
> --
>
>

Avital Oliver

unread,
Jan 14, 2013, 4:05:33 PM1/14/13
to meteo...@googlegroups.com
I copied this code into a server file in an empty project and all was printed as expected (though the app didn't load since you didn't call next() at the end of the middleware).

Could it be that you placed this within a Meteor.startup() block? That would get executed after the server loads its own middleware which blocks any additional ones.

On Sun, Jan 13, 2013 at 8:20 PM, Tim Heckel <timh...@gmail.com> wrote:

Tim Heckel

unread,
Jan 15, 2013, 5:47:51 PM1/15/13
to meteo...@googlegroups.com
Thanks Avital. You were correct; I had my code in a startup function. Thanks very much!

In the world I come from (C# / .NET), you typically can get all the client's cookies regardless of its domain on the server. The cookieParser looks to give me all cookies bound to the current domain. I will keep digging, but what I really need to know is whether a cookie set at a different domain is present.

Does that make sense?
Reply all
Reply to author
Forward
0 new messages