Fetching request body parameters in a get-route?

26 views
Skip to first unread message

Daniel Andréasson

unread,
Apr 11, 2015, 2:19:31 AM4/11/15
to expre...@googlegroups.com
Hey.

I'm having problems and I'm not sure if this is possible but it would be really nice if it did.
As of right now, we're having an application where you can chat with each other independant of which site the peers are on.
The problem is that it's per request-based, meaning if I request a new site the chat will be empty when that page is loaded.

Since the div that holds the chat is called the same on every site I wondered if you could just make express pass that parameter as a sessionvariable that I can initiate the div with on body load.
I haven't been able to figure out a way to do this without doing a post-route which complicates it alot.

Does anyone have a good easy solution for this?

Something in the way of:
app.use(function (req, res, next) {
  req
.session.conversation = req.body.conversation;
 
next()
});

and then just having something like this on every site
body(onload=setChat('#{session.conversation}', domID)")

Thanks in advance.
Daniel

Alexander Behrens

unread,
Apr 11, 2015, 8:25:01 AM4/11/15
to expre...@googlegroups.com
Storing a conversation in a session is a bad idea. The cookie is sent with every HTTP request. So the longer a conversation gets the bigger the HTTP header is. What you can do however, is store a session ID on client side and load the conversation from a database server side on every request.

--
You received this message because you are subscribed to the Google Groups "Express" group.
To unsubscribe from this group and stop receiving emails from it, send an email to express-js+...@googlegroups.com.
To post to this group, send email to expre...@googlegroups.com.
Visit this group at http://groups.google.com/group/express-js.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages