Skip to content

Commit

Permalink
add ssl flag to pgpool when env prod
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Dec 4, 2024
1 parent 00cd692 commit 3ed8832
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions backoffice/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ const Components = {
const authProvider = new AuthProvider();

const start = async () => {
const PgStore = connectPgSimple(session);
const sessionStore = new PgStore({
pool: new pg.Pool({
host: process.env.DB_HOST || "localhost",
user: process.env.DB_USERNAME || "blue-carbon-cost",
password: process.env.DB_PASSWORD || "blue-carbon-cost",
database: process.env.DB_NAME || "blc-dev",
port: 5432,
ssl:
process.env.NODE_ENV === "production"
? { rejectUnauthorized: false }
: false,
}),
tableName: BACKOFFICE_SESSIONS_TABLE,
});
await dataSource.initialize();
const app = express();

Expand Down Expand Up @@ -168,26 +183,16 @@ const start = async () => {
},
});

const PgStore = connectPgSimple(session);
const sessionStore = new PgStore({
pool: new pg.Pool({
host: process.env.DB_HOST || "localhost",
user: process.env.DB_USERNAME || "blue-carbon-cost",
password: process.env.DB_PASSWORD || "blue-carbon-cost",
database: process.env.DB_NAME || "blc-dev",
port: 5432
}),
tableName: BACKOFFICE_SESSIONS_TABLE,
});

const customRouter = express.Router();
// Redirect to the app's login page
customRouter.get('/login', (req, res) => {
res.redirect('/auth/signin');
customRouter.get("/login", (req, res) => {
res.redirect("/auth/signin");
});

const sessionCookieName = process.env.BACKOFFICE_SESSION_COOKIE_NAME as string;
const sessionCookieSecret = process.env.BACKOFFICE_SESSION_COOKIE_SECRET as string;
const sessionCookieName = process.env
.BACKOFFICE_SESSION_COOKIE_NAME as string;
const sessionCookieSecret = process.env
.BACKOFFICE_SESSION_COOKIE_SECRET as string;
const adminRouter = AdminJSExpress.buildAuthenticatedRouter(
admin,
{
Expand All @@ -204,8 +209,8 @@ const start = async () => {
cookie: {
secure: false,
maxAge: undefined,
}
}
},
},
);

app.use(admin.options.rootPath, adminRouter);
Expand Down

0 comments on commit 3ed8832

Please sign in to comment.