Good day! There is a node.js server, which sends cookie after authorization. Server response contains "Set-cookie", but the browser doesn't take them. Requests to server send by JQuery's AJAX.
Server:
var express = require('express'),
http = require('http'),
app = express(),
mysql = require('mysql'),
cookie = require('cookie');
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, HEAD');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type, Authorization');
res.setHeader('Access-Control-Allow-Credentials', true);
next();
});
app.post('/login', jsonParser, (request, response) => {
if(!request.body) return response.sendStatus(400);
var dbHandler = mysql.createPool({
database : config.get('db:database'),
host : config.get('db:host'),
user : config.get('db:user'),
password : config.get('db:password'),
insecureAuth: config.get('db:insecureAuth'),
});
getUser(dbHandler, request.body.username, request.body.password, function(id){
getPlace(dbHandler, id, function(place){
getItems(dbHandler, place['id'], place['url'], function(items){
response.cookie('logined', true, { expires: new Date(Date.now() + 1000*60*60*24), domain:'localhost:8000/', httpOnly: true });
response.writeHead(200, {'Content-Type': 'text/html; charset=utf8'});
response.send('Ok');
});
});
});
})
app.listen(config.get('port'), () => {
console.log('server is listening on', config.get('port'));
})