-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
58 lines (48 loc) · 1.78 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
51
52
53
54
55
56
57
58
/*jshint esversion: 6 */
//INITIALIZE DEPENDENCIES
const express = require("express"); //Express.js
const app = express(); //Express.js app
const MongoClient = require("mongodb").MongoClient; //MongoDB client
const bodyParser = require("body-parser"); //To parse URL information
const path = require("path"); //Path - inside NODE
const hbs = require("./utils/hbs"); //Handlebars
const passport = require("passport"); //passportjs
const GoogleStrategy = require("passport-google-oauth").OAuthStrategy; //passportjs Google strategy
const keys = require("./config/keys");
const session = require("express-session");
const mongoose = require("mongoose");
const passportSetup = require("./config/passport-setup");
//set to use handlebars as view engine
app.set("view engine", "hbs");
//Setting the path names and middleware
hbs.registerPartials(__dirname + "/views/partials");
//To use CSS files:
app.use(express.static(path.join(__dirname + "/public")));
//Initialize session cookies
app.use(
session({
secret: keys.session.cookieKey,
resave: false,
saveUninitialized: true
})
);
//Port number and start listening on PORT
const PORT = 3000;
var server = app.listen(PORT, () => {
console.log("app listening on port: " + PORT);
});
//Initialize Passport
app.use(passport.initialize());
app.use(passport.session());
//Initialize the routes this app will do
const mainRoutes = require("./routes/main-routes");
const authRoutes = require("./routes/oauth-routes");
const adminRoutes = require("./routes/admin-routes");
const sockets = require("./utils/sockets")(server);
app.use("/", mainRoutes);
app.use("/auth", authRoutes);
app.use("/admin", adminRoutes);
//Initialize Mongoose to connect to DB using URI in keys
mongoose.connect(keys.mongodb.dbURI, () => {
console.log("connected to mongodb");
});