Express-Session not working when client using Serve

When I ran the React application through npm start with localhost:3000, the sessions on the backend worked and saved.

When I built the application using "npm build" and launched using "serve -s build". (same address: localhost:3000). The sessions in the backend not saved.

Sessions Setup:

const sessionMiddleware = session({
  key: 'userId',
  secret: 'superdupersecret',
  resave: false,
  proxy: true,
  saveUninitialized: false,
  store: new RedisStore({
    client: redisClient
  }),
  cookie: {
    expires: 60 * 60 * 24 * 1000 * 7
  }
})

CORS:

app.use(function (req, res, next) {
    res.setHeader('Access-Control-Allow-Origin', process.env.BOT_DASHBOARD_URL)
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE')
    res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type')
    res.setHeader('Access-Control-Allow-Credentials', true)
    next()
  })


Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations