cookies middleware tests
This commit is contained in:
parent
77dadf7e1c
commit
a092e9a715
1 changed files with 11 additions and 6 deletions
|
|
@ -16,22 +16,27 @@ const port = process.env.PORT || 3000;
|
||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
app.use(cors({origin: 'http://127.0.0.1:4200', credentials: true}));
|
app.use(cors({origin: 'http://127.0.0.1:4200', credentials: true}));
|
||||||
app.use(cookieParser());
|
app.use(cookieParser());
|
||||||
|
io.use(function(socket, next){
|
||||||
|
const session = auth.getSession(socket.request);
|
||||||
app.get('/', (req, res) => {
|
|
||||||
const session = auth.getSession(req);
|
|
||||||
const getUsername = auth.getUsername(session);
|
const getUsername = auth.getUsername(session);
|
||||||
if (getUsername === -1) {
|
if (getUsername === -1) {
|
||||||
//sendError(res, 'not authenticated');
|
//sendError(res, 'not authenticated');
|
||||||
}
|
}
|
||||||
//auth.setSessionCookie(req, res, session);
|
auth.setSessionCookie(socket.request, socket.request.res || {}, next);
|
||||||
res.sendFile(__dirname + '/index.html');
|
});
|
||||||
|
|
||||||
|
app.get('/', (req, res) => {
|
||||||
|
res.sendFile(__dirname + '/index.html');
|
||||||
});
|
});
|
||||||
|
|
||||||
io.on('connection',socket => {
|
io.on('connection',socket => {
|
||||||
let users = {}
|
let users = {}
|
||||||
|
|
||||||
|
const session = auth.getSession(socket.request);
|
||||||
|
const getUsername = auth.getUsername(session);
|
||||||
|
|
||||||
|
console.log(getUsername);
|
||||||
|
|
||||||
socket.on('user', (userData) => {
|
socket.on('user', (userData) => {
|
||||||
console.log(`${getUsername} joined the chat.`);
|
console.log(`${getUsername} joined the chat.`);
|
||||||
users[socket.id] = getUsername;
|
users[socket.id] = getUsername;
|
||||||
|
|
|
||||||
Reference in a new issue