Rick
Rick
RRailway
Created by Rick on 2/13/2024 in #✋|help
MongoDB connection
Actually I seem to have fixed that issuen now, but he app still crashes. It runs locally no problem, and the logs don't show any issues 🤔
9 replies
RRailway
Created by Rick on 2/13/2024 in #✋|help
MongoDB connection
I try changing it based on a few comments on stackoverflow and medium, but can't resolve it
9 replies
RRailway
Created by Rick on 2/13/2024 in #✋|help
MongoDB connection
It seems be something to do with MongoStore, but it's not something I'm familiar with.
9 replies
RRailway
Created by Rick on 2/13/2024 in #✋|help
MongoDB connection
require("dotenv").config(); const express = require("express"); const cors = require("cors"); const methodOverride = require("method-override"); const expressLayout = require("express-ejs-layouts"); const cookieParser = require("cookie-parser"); const session = require("express-session"); const mongoose = require("mongoose"); const MongoStore = require("connect-mongo"); // const dbString = process.env.MONGO_DB_URI; const connection = mongoose.createConnection(process.env.MONGO_DB_URI); const helmet = require("helmet"); const app = express(); const PORT = 3000 || process.env.PORT; const connectDB = require("./server/config/db.js"); const { isActiveRoute } = require("./server/helpers/routeHelpers.js"); const sessionStore = MongoStore.create({ client: connection.getClient(), collection: "session", }); // Connect to Databse connectDB(); app.use(express.urlencoded({ extended: true })); app.use(express.json()); app.use(cookieParser()); app.use(cors()); app.use(methodOverride("_method")); app.use( session({ secret: "", resave: false, saveUninitialized: true, store: sessionStore, }) ); app.use(express.static("public")); // Templating Engine app.use(expressLayout); app.set("layout", "./layouts/main"); app.set("view engine", "ejs"); app.locals.isActiveRoute = isActiveRoute; app.use("/", require("./server/routes/main.js")); app.use("/", require("./server/routes/admin.js")); app.listen(PORT, () => { console.log(App listening on port ${PORT}); }); // Security app.use( helmet.contentSecurityPolicy({ directives: { "script-src": ["'self'", "code.jquery.com", "cdn.jsdelivr.net"], }, }) );
9 replies
RRailway
Created by Rick on 2/13/2024 in #✋|help
MongoDB connection
Error: Cannot init client. Please provide correct options at new MongoStore (/app/node_modules/connect-mongo/build/main/lib/MongoStore.js:123:19) at MongoStore.create (/app/node_modules/connect-mongo/build/main/lib/MongoStore.js:140:16) at Object.<anonymous> (/app/app.js:21:33) at Module._compile (node:internal/modules/cjs/loader:1256:14) at Module._extensions..js (node:internal/modules/cjs/loader:1310:10) at Module.load (node:internal/modules/cjs/loader:1119:32) at Module._load (node:internal/modules/cjs/loader:960:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:86:12) at node:internal/main/run_main_module:23:47 Node.js v18.18.2
9 replies