Думаю, что проблема простая, но так первый раз использую socket.io воможно что-то некорректно.
loopback server.js
// start the server if `$ node server.js`
if (require.main === module)
app.io = require('socket.io')(app.start());
});
routes.js
//log a user in
app.post('/login', function(req, res) {
User.login({
email: req.body.email,
password: req.body.password
}, 'user', function(err, token) {
if (err) {
if(err.details && err.code === 'LOGIN_FAILED_EMAIL_NOT_VERIFIED'){
res.render('reponseToTriggerEmail', {
title: 'Login failed',
content: err,
redirectToEmail: '/api/users/'+ err.details.userId + '/verify',
redirectTo: '/',
redirectToLinkText: 'Click here',
userId: err.details.userId
});
} else {
app.io.emit('login-response', { loginError: 'Login failed. Wrong username or password'});
}
return;
}
res.render('home', {
email: req.body.email,
accessToken: token.id,
redirectUrl: '/api/users/change-password?access_token=' + token.id
});
});
});
server {
listen 443 ssl http2;
server_name ...;
ssl_certificate ...;
ssl_certificate_key ...;
error_log /var/log/nginx/..;
access_log /var/log/nginx/...;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://...:3000/;
}
}
<script src=js/jquery.min.js></script>
<script src=js/socket.io.js></script>
<script>
var socket = io.connect();
socket.on('login-response', function (msg) {
console.log(msg);
$('#login-response').html(msg.loginError)
});
</script>