Session data is not persisting for multiple calls. It is going through localhost. I have tried making the cookie not secure. Every call has the value of 1 and it never changes. Using latest versions of all packages. Please help me

// JS
$.ajax({
    type: "GET",
    url: "http://localhost:8080/test/",
    success: (result) => { console.log(result); }
});
// NODE
var express = require("express");
var path = require('path');
var cors = require('cors');
var hash = require('object-hash');
var session = require('express-session');
var app = express();
app.use(express.json());
app.use(cors());
app.use(express.urlencoded({extended: true}));
app.use(session({
    resave: false,
    saveUninitialized: true,
    secret: 'keepThemSweatyKidsAway',
    cookie: { 
        secure: false
    }
}));


app.use((req, res, next) => {
    if (!req.session.views) {
        req.session.views = 0;
    }

    req.session.views = req.session.views + 1;
    next();
});

app.get('/test/', function (req, res, next) {
    console.log(req.session);
    res.send('you viewed this page ' + req.session.views + ' times');
});

app.listen(PORT, () => {
    console.log("Server listening on: https://sweaty-kids.herokuapp.com:%s", PORT);
});

0 Answers