Node.JS notifications on my site in PHP

I am developing a website in PHP. Now I would just like to add a notification system. Imagine being like a friendship with Facebook: when I get a friend’s request, I get a notification too.

Of course, I know a bit of Node.JS and Socket.IO, but the complex part seems to be the implementation with PHP.

What do I mean for now:

1. user sends friend request 2. in my PHP code, I cURL my Node.JS service: "/notification?friendid=9634963478" 3. user with id 9634963478 should get a notification 

I ran into a problem:

How do I log in with the same credentials on Node.js? So, in principle, none of the users, except me, can receive messages?

I'm not looking for code, but rather "enlightenment" from some guru.

+4
source share
1 answer

use the same session storage file in your nodejs application and pass the cookie together, it should be in the same subdomain, for example, msg.example.com, where the cookie is set by your php layer on .example.com

Take a look at express.session - here is an example using redis:

  var RedisStore = require('connect-redis')(express); app.use(express.session({ store: new RedisStore({ host: cfg.redis.host, db: cfg.redis.db }), secret: 'foobar' })); 

Video on using sessions: http://nodetuts.com/tutorials/13-authentication-in-express-sessions-and-route-middleware.html

+1
source

Source: https://habr.com/ru/post/1435785/


All Articles