-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathapp.js
97 lines (81 loc) · 2.98 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
var express = require("express"),
app = express(),
User = require("./models/user"),
flash = require("connect-flash"),
seedDB = require("./seeds"),
LocalStrategy = require("passport-local"),
methodOverride = require("method-override"),
FacebookStrategy = require('passport-facebook').Strategy,
Comment = require("./models/comment"),
mongoose = require("mongoose"),
passport = require("passport"),
bodyParser = require("body-parser"),
Thriftstore = require("./models/thriftstore"),
moment = require("moment"),
config = require("./config.js"),
fileUpload = require('express-fileupload'),
nodemailer = require('nodemailer');
//requiring routes
var commentRoutes = require("./routes/comments"),
thriftRoutes = require("./routes/thriftstores"),
indexRoutes = require("./routes/index"),
uploadRoutes = require("./routes/upload"),
authenticationRoutes = require("./routes/authentication"),
apiRoutes = require("./routes/api");
// seedDB(); //seed the database
mongoose.connect("mongodb://" + config.db.username + ":" + config.db.password + "@host:localhost/thrift_finder");
app.use(bodyParser.urlencoded({extended:true}));
app.use(express.static(__dirname + "/public"));
app.use(fileUpload());
app.set("view engine", "ejs");
app.use(methodOverride("_method"));
app.use(flash());
//PASSPORT CONFIGURATION
app.use(require("express-session")({
secret: config.express.secret,
resave: false,
saveUninitialized: false
}));
app.use(passport.initialize());
app.use(passport.session());
passport.use(new LocalStrategy(User.authenticate()));
//facebook
passport.use(new FacebookStrategy({
clientID: config.facebook.clientID,
clientSecret: config.facebook.clientSecret,
callbackURL: "https://thriftfindr.com/auth/facebook/callback",
profileFields: ['id', 'name','picture.type(large)', 'emails', 'displayName'],
},
function(accessToken, refreshToken, profile, cb) {
User.findOrCreate(profile, function (err, user) {
console.log('###user###', user);
return cb(err, user);
});
}
));
// passport.serializeUser(User.serializeUser());
// passport.deserializeUser(User.deserializeUser());
passport.serializeUser(function(user, cb) {
cb(null, user);
});
passport.deserializeUser(function(obj, cb) {
cb(null, obj);
});
//flash
app.use(function(req, res, next){
res.locals.currentUser = req.User;
res.locals.error = req.flash("error");
res.locals.success = req.flash("success");
next();
});
//shortened routes
app.use("/", indexRoutes);
app.use("/about", indexRoutes);
app.use("/thriftstores/:id/comments", commentRoutes);
app.use("/thriftstores", thriftRoutes);
app.use("/auth", authenticationRoutes);
app.use("/api", apiRoutes);
app.use("/upload", uploadRoutes)
app.listen(7000, function(){
console.log("The ThriftFindr server has started!");
});