-
Notifications
You must be signed in to change notification settings - Fork 10
/
app.js
74 lines (59 loc) · 1.94 KB
/
app.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
require("dotenv").config();
const session = require("express-session");
const passport = require("passport");
const express = require("express");
const ejsMate = require("ejs-mate");
const mongoose = require("mongoose");
require("https").globalAgent.options.rejectUnauthorized = false;
const app = express();
app.use(express.static("public"));
app.use(express.static("uploaded_docs"));
app.use(express.urlencoded({ extended: true }));
app.set("view engine", "ejs");
app.engine("ejs", ejsMate);
app.use(
session({
secret: process.env.SECRET,
resave: false,
saveUninitialized: false,
// store: mongoStore.create({
// mongoUrl: process.env.PASS
// })
})
);
app.use(passport.initialize());
app.use(passport.session());
mongoose.set('strictQuery', false);
mongoose.connect(String(process.env.DB_URL),{ useNewUrlParser: true , useUnifiedTopology: true}).then(()=>{
console.log("connection established");
}); // Running on a remote server
const User = require("./schema/user");
passport.use(User.createStrategy());
passport.serializeUser(function (user, done) {
done(null, user.id);
});
passport.deserializeUser(function (id, done) {
User.findById(id, function (err, user) {
done(err, user);
});
});
const strategy = require("./src/strategy");
passport.use(strategy);
////// Routes /////////
const authRoute = require("./routes/auth");
const homeRoute= require("./routes/home");
const fetchRoute = require("./routes/fetch");
const addRoute = require("./routes/addItem");
const chatRoute = require("./routes/chat");
const websiteRoute = require("./routes/website");
const profileRoute = require("./routes/profile");
app.use('/auth/google', authRoute);
app.use("/", homeRoute);
app.use("/", fetchRoute);
app.use("/", addRoute);
app.use("/", chatRoute);
app.use("/", websiteRoute);
app.use("/", profileRoute);
app.listen(process.env.PORT || 8080, function () {
console.log("Server running on port "+ process.env.PORT || 8080);
});