-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
50 lines (44 loc) · 1.5 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require("dotenv").config();
const auth = require("./auth.js");
const routes = require("./routes.js");
const express = require("express");
let app = express();
let pug = require("pug");
const port = process.env.PORT || 3000;
const session = require("express-session");
const passport = require("passport");
const mongodb = require("mongodb");
const MongoClient = mongodb.MongoClient;
const ObjectId = require("mongodb").ObjectID;
const http = require("http").createServer(app);
const MongoStore = require("connect-mongo")(session);
const store = new MongoStore({ url: process.env.DB });
app.use("/public", express.static(process.cwd() + "/public"));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
MongoClient.connect(
process.env.DB, { useUnifiedTopology: true },
(err, client) => {
if (err) return console.log(err);
let db = client.db("cluster0");
db ? console.log("no error") : console.log("error");
app.use(
session({
secret: process.env.SESSION_SECRET,
resave: true,
saveUninitialized: true,
cookie: { secure: false },
key: "connect.sid",
store: store,
})
);
app.set("view engine", "pug");
app.use(passport.initialize());
app.use(passport.session());
auth(app, db);
routes(app, db);
http.listen(port, () => {
console.log("listening on port", port);
});
}
);