Created
September 19, 2022 13:37
-
-
Save Tosinkoa/3528d230c54a91da9003510fd984f1e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import express from "express" | |
import rootRoute from "./src/root_Route.js" | |
import cookieParser from "cookie-parser" | |
import passport from "passport" | |
import connectPgSimple from "connect-pg-simple" | |
import session from "express-session" | |
import dotenv from "dotenv" | |
import cors from "cors" | |
import "./src/LIB/DB-Client.js" | |
import "./src/PASSPORT_STRATEGY/google-auth-strategy.js" | |
import "./src/PASSPORT_STRATEGY/facebook-auth-strategy.js" | |
import { scheduleJob } from "node-schedule" | |
import pool from "./src/LIB/DB-Client.js" | |
dotenv.config() | |
const app = express() | |
app.use( | |
cors({ | |
origin: ["http://localhost:3000", "https://nairaonly-frontend.netlify.app"], | |
credentials: true, | |
methods: "GET, PUT, POST, DELETE", | |
optionsSuccessStatus: 200 | |
}) | |
) | |
const PgStore = connectPgSimple(session) | |
const store = new PgStore({ schemaName: "hidden", createTableIfMissing: true }) | |
app.use(express.json()) | |
app.use(cookieParser()) | |
app.set("trust proxy", 1) | |
app.use( | |
session({ | |
store: store, | |
secret: "myscecret", | |
saveUninitialized: false, | |
resave: false, | |
cookie: { | |
maxAge: 1000 * 60 * 60 * 24, | |
secure: true, | |
httpOnly: true, | |
sameSite: "none", | |
}, | |
}) | |
) | |
app.get("/", (req, res) => { | |
const userId = req.session.user ?? req.user | |
res.send("API Running...") | |
}) | |
app.use(passport.initialize()) | |
app.use(passport.session()) | |
rootRoute(app) | |
const PORT = process.env.PORT || 4000 | |
app.listen(PORT, (req, res) => console.log(`Server running on PORT:${PORT}...`)) | |
//---------------This is where I connected the client----------------- | |
import pkg from 'pg'; | |
const { Pool } = pkg; | |
const pool = new Pool({ | |
user: process.env.USER, | |
host: process.env.HOST, | |
database: process.env.DATABASE, | |
password: process.env.PASSWORD, | |
port: process.env.PORT, | |
ssl: { | |
logging: false, | |
rejectUnauthorized: false | |
} | |
}) | |
console.log("Connected to database... ✅✅✅") | |
export default pool | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment