-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
98 lines (83 loc) · 2.58 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Required dependencies
require("dotenv").config();
const express = require('express');
const app = express();
const passport = require('passport');
var db = require("./models/");
var https = require("https");
const GoogleStrategy = require('passport-google-oauth20');
const cookieSession = require('cookie-session');
var exphbs = require("express-handlebars");
var PORT = process.env.PORT || 3000;
// cookieSession config
app.use(cookieSession({
maxAge: 24 * 60 * 60 * 1000, // One day in milliseconds
keys: ['randomstringhere']
}));
//middleware
app.use(express.urlencoded({
extended: false
}));
app.use(express.json());
app.use(express.static("public"));
app.use(passport.initialize()); // Used to initialize passport
app.use(passport.session()); // Used to persist login sessions
// Handlebars
app.set("view engine", "handlebars");
app.engine(
"handlebars",
exphbs({
defaultLayout: "main"
})
);
//routes
require("./routes/apiRoutes")(app, passport);
require("./routes/htmlRoutes")(app, passport);
require("./routes/authRoutes")(app,passport);
// google Strategy config
passport.use(new GoogleStrategy({
clientID: '80481251698-gjc9859qica9mdfdp58qo1dnofa0tjmn.apps.googleusercontent.com',
clientSecret: 'Buf9mfJiMoTOjwVE3QUrWcGY',
callbackURL: 'http://localhost:3000/auth/google/callback'
},
(accessToken, refreshToken, profile, done) => {
//log the user profile so we know the user has the information we need
//useful for figuring out what data we can access through handlebars parameters
// check menu.handlebars for an example
done(null, profile); // passes the profile data to serializeUser
}
));
// Used to stuff a piece of information into a cookie
passport.serializeUser((user, done) => {
done(null, user);
});
// Used to decode the received cookie and persist session
passport.deserializeUser((user, done) => {
done(null, user);
});
//
function createNewUser(user){
$.ajax({
method: "POST",
url: "/api/users/" + user.userId
});
}
var syncOptions = {
force: false
};
// If running a test, set syncOptions.force to true
// clearing the `testdb`
if (process.env.NODE_ENV === "test") {
syncOptions.force = true;
}
// Starting the server, syncing our models ------------------------------------/
db.sequelize.sync(syncOptions).then(function () {
app.listen(PORT, function () {
console.log(
"==> 🌎 Listening on port %s. Visit http://localhost:%s/ in your browser.",
PORT,
PORT
);
});
});
module.exports = app;