Skip to content

Commit

Permalink
something is up with sessions not sure what the deal is
Browse files Browse the repository at this point in the history
  • Loading branch information
booherbg committed Dec 3, 2024
1 parent f857dd9 commit 14c1205
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,17 @@ import passport from './config/passport.js';
import todosRouter from './routes/todos.router.js';
import userRouter from './routes/user.router.js';
import path from 'path';

import session from 'express-session';
const app = express();
const PORT = process.env.PORT || 5001;

// Cookie session middleware
app.use(cookieSession({
name: 'session',
keys: [process.env.SESSION_SECRET || 'your-secret-key'],
maxAge: 24 * 60 * 60 * 1000, // 24 hours
secure: process.env.NODE_ENV === 'production',
sameSite: 'strict'
// use express session middleware
app.use(session({
secret: process.env.SESSION_SECRET || 'your-secret-key',
resave: false,
saveUninitialized: false,
}));

// Add these compatibility methods for Passport
app.use((req, res, next) => {
if (req.session && !req.session.regenerate) {
req.session.regenerate = (cb) => cb();
}
if (req.session && !req.session.save) {
req.session.save = (cb) => cb();
}
next();
});

// Other middleware
app.use(express.static('dist'));
app.use(express.json());
Expand All @@ -38,10 +25,10 @@ app.use(passport.session());
app.use('/api/users', userRouter);
app.use('/api/todos', todosRouter);

// app.get('*', (req, res) => {
// console.log('sending index.html')
// res.sendFile(path.resolve('dist', 'index.html'))
// });
app.get('*', (req, res) => {
console.log('sending index.html')
res.sendFile(path.resolve('dist', 'index.html'))
});

app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
Expand Down

0 comments on commit 14c1205

Please sign in to comment.