forked from ivanavi2/hf-delivery-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
88 lines (77 loc) · 3.03 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
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const passport = require('passport');
const LocalStrategy = require('passport-local');
const methodOverride = require("method-override");
const flash = require('connect-flash');
const Order = require("./models/order");
const Customer = require("./models/customer");
const Vendor = require("./models/vendor");
const middlewareObj = require('./middleware');
const storeRoutes = require("./routes/store");
const indexRoutes = require("./routes/index");
const cartRoutes = require("./routes/cart");
const orderRoutes = require("./routes/order");
const chatRoutes = require("./routes/chat");
const vendorRoutes = require("./routes/vendor");
const notificationRoutes = require("./routes/notification");
/*
const customerRoutes = require("./routes/customer");
const cartRoutes = require("./routes/cart"); */
//"mongodb://localhost/appdev_test" || process.env.DATABASEURL
//process.env.DATABASEURL || "mongodb://localhost/appdev_test"
//Mongodb config
//mongodb+srv://bizbuzbiz:ivantehteh1@cluster0.gumfa.mongodb.net/hf-delivery?retryWrites=true&w=majority
mongoose.connect("mongodb://localhost/appdev_test" || process.env.DATABASEURL ,
{useNewUrlParser: true,
useUnifiedTopology: true})
.then(() => console.log("Connected to DB!"))
.catch((error) => console.log(error.message));
/* mongoose.connect("mongodb+srv://bizbuzbiz:ivantehteh1@cluster0.gumfa.mongodb.net/hf-delivery?retryWrites=true&w=majority",
{useNewUrlParser: true,
useUnifiedTopology: true})
.then(() => console.log("Connected to DB!"))
.catch((error) => console.log(error.message)); */
//Other config
app.use(methodOverride("_method"));
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static(__dirname + "/public"));
app.use(flash());
app.set("view engine", "ejs");
//Passport config
app.use(require("express-session")({
secret: "ivanteholimauais",
resave: false,
saveUninitialized: false
}))
app.use(passport.initialize());
app.use(passport.session());
passport.use("customerLocal", new LocalStrategy({passReqToCallBack: true},Customer.authenticate()));
passport.serializeUser(Customer.serializeUser());
passport.deserializeUser(Customer.deserializeUser());
passport.use("vendorLocal", new LocalStrategy({passReqToCallBack: true},Vendor.authenticate()));
passport.serializeUser(Vendor.serializeUser());
passport.deserializeUser(Vendor.deserializeUser());
app.use((req, res, next) => {
res.locals.role = req.session.strategy;
res.locals.currentUser = req.user || req.session.currentUser;
res.locals.error = req.flash("error");
res.locals.success = req.flash("success");
next();
});
app.use(indexRoutes);
app.use(storeRoutes);
app.use(cartRoutes);
app.use(orderRoutes);
app.use(chatRoutes);
app.use(vendorRoutes);
app.use(notificationRoutes);
/* app.use(vendorRoutes);
app.use(customerRoutes);
app.use(cartRoutes);
*/
app.listen(process.env.PORT || 3000, () => {
console.log("Listening to hfd_copy");
})