0

I'm using express and trying to set up sessions with DynamoDB on AWS. For some reason, I keep having tons of random sessions generated on a single page load. It seems somewhat related to this Why am I getting error for apple-touch-icon-precomposed.png but I tried creating a file in the root folder with these names and adding this to the head of my html/pug file

link(rel='shortcut icon' href='/favicon.ico' type='image/x-icon')
link(rel='apple-touch-icon' href='/apple-touch-icon.png')
link(rel='apple-touch-icon' sizes='57x57' href='/apple-touch-icon-57x57.png')
link(rel='apple-touch-icon' sizes='72x72' href='/apple-touch-icon-72x72.png')
link(rel='apple-touch-icon' sizes='76x76' href='/apple-touch-icon-76x76.png')
link(rel='apple-touch-icon' sizes='114x114' href='/apple-touch-icon-114x114.png')
link(rel='apple-touch-icon' sizes='120x120' href='/apple-touch-icon-120x120.png')
link(rel='apple-touch-icon' sizes='144x144' href='/apple-touch-icon-144x144.png')
link(rel='apple-touch-icon' sizes='152x152' href='/apple-touch-icon-152x152.png')
link(rel='apple-touch-icon' sizes='180x180' href='/apple-touch-icon-180x180.png')

but now, I get like 8 requests at a time instead of 3. Additionally, on every new apple touch icon request for the favicon, apple-touch-icon.png and apple-touch-icon-precomposed.png, it's creating a new session in my dynamodb table, even tho new page loads/refreshes did not. How do I either stop the apple requests or get my dynamodb to stop generating duplicate sessions? Or does it not matter that I have extraneous sessions in my db other than garbage data?

Should I not have my session creation in my server.js file and just make it on certain routes? I previously had sessions in my server.js file and didn't have this issue so I'm really confused. Below is the printout in my console. It does not seem like my session id is being replaced when the duplicate sessions are created in my dynamodb.

start: path= /apple-touch-icon-precomposed.png
generate session id
start: path= /apple-touch-icon.png
generate session id
start: path= /favicon.ico
generate session id
start: path= /login
generate session id
start: path= http localhost:3000 /favicon.ico
start: path= http localhost:3000 /apple-touch-icon-57x57.png
start: path= http localhost:3000 /apple-touch-icon.png
start: path= http localhost:3000 /apple-touch-icon-72x72.png
start: path= http localhost:3000 /apple-touch-icon-76x76.png
start: path= http localhost:3000 /apple-touch-icon-114x114.png
start: path= http localhost:3000 /apple-touch-icon-180x180.png
start: path= http localhost:3000 /apple-touch-icon-152x152.png
start: path= http localhost:3000 /apple-touch-icon-144x144.png
start: path= http localhost:3000 /apple-touch-icon-120x120.png

server.js file

app.use((req, res, next) => {console.log("start: path=", req.path); next();});

app.use(session({
    genid: (req) => {
        console.log('generate session id') 
        return uuidv4() // use UUIDs for session IDs
    },
        cookie: {
         secure: true,
      // httpOnly: true // false for now on local host
    },
    store: new DynamoDBStore(options), 
    secret: 'secretkey',
    resave: false,
    cookie: {
        maxAge: 24*21*60*60*1000 // 21 days
    },
    saveUninitialized: false,
    // name: 'id',  
    rolling: true
}));
user3768258
  • 115
  • 1
  • 10

0 Answers0