mirror of
https://github.com/R0m1k3/Socialflow.git
synced 2026-10-11 17:26:45 +02:00
Improve session management by persisting user sessions in production
Update server configuration to use connect-pg-simple for PostgreSQL session storage in production environments and MemoryStore for development. Replit-Commit-Author: Agent Replit-Commit-Session-Id: ae4037a0-2a6f-4530-9bac-79b543286bda Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/397bca8c-984f-43ff-841a-10897aeb8140/ae4037a0-2a6f-4530-9bac-79b543286bda/G8GuKB7
This commit is contained in:
1 parent
d7ade0982c
commit
747469bc4c
3 files changed
+21
-5
No files matched your search
@@ -1,5 +1,7 @@
|
||||
import express, { type Request, Response, NextFunction } from "express";
|
||||
import session from "express-session";
|
||||
import connectPgSimple from "connect-pg-simple";
|
||||
import pg from "pg";
|
||||
import passport from "./auth";
|
||||
import { registerRoutes } from "./routes";
|
||||
import { setupVite, serveStatic, log } from "./vite";
|
||||
@@ -7,6 +9,7 @@ import { schedulerService } from "./services/scheduler";
|
||||
import { ensureAdminUserExists } from "./init-admin";
|
||||
|
||||
const app = express();
|
||||
const PgSession = connectPgSimple(session);
|
||||
|
||||
declare module 'http' {
|
||||
interface IncomingMessage {
|
||||
@@ -28,7 +31,19 @@ if (!process.env.SESSION_SECRET) {
|
||||
// Déterminer si on utilise HTTPS basé sur APP_URL
|
||||
const isHttps = process.env.APP_URL?.startsWith('https://') || false;
|
||||
|
||||
// Configuration du store de session pour production
|
||||
const sessionStore = process.env.NODE_ENV === 'production' && process.env.DATABASE_URL
|
||||
? new PgSession({
|
||||
pool: new pg.Pool({
|
||||
connectionString: process.env.DATABASE_URL,
|
||||
}),
|
||||
tableName: 'session',
|
||||
createTableIfMissing: true,
|
||||
})
|
||||
: undefined; // MemoryStore par défaut en dev
|
||||
|
||||
app.use(session({
|
||||
store: sessionStore,
|
||||
secret: process.env.SESSION_SECRET || 'your-secret-key-change-me',
|
||||
resave: false,
|
||||
saveUninitialized: false,
|
||||
|
||||
Reference in new issue
Block a user