-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
57 lines (48 loc) · 1.54 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
require('dotenv').config()
var express = require("express"),
app = express(),
methodoverride = require("method-override"),
bodyparser = require("body-parser"),
mongoose = require("mongoose"),
passport = require("passport"),
LocalStrategy = require("passport-local"),
expresssanitizer = require("express-sanitizer");
//SCHEMA
var Image = require("./models/image");
var User = require("./models/user");
//ROUTES
var imageRoutes = require("./routes/images"),
indexRoutes = require("./routes/indexs");
mongoose.Promise = global.Promise;
mongoose.set('useFindAndModify', false);
var dbURl = process.env.DATABASEURL || "mongodb://localhost/restful_blog_app" //DATABASE
mongoose.connect(process.env.DATABASEURL, {
useNewUrlParser: true,
useUnifiedTopology: true
});
app.use(bodyparser.urlencoded({extended: true}));
app.use(expresssanitizer());
app.set("view engine", "ejs");
app.use(express.static("public"));
app.use(methodoverride("_method"));
//PASSPORT CONFIGURATION
app.use(require("express-session")({
secret: "shhhhh",
resave: false,
saveUninitialized: false
}));
app.use(passport.initialize());
app.use(passport.session());
passport.use(new LocalStrategy(User.authenticate()));
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());
app.use(function(req, res, next){
res.locals.currentUser = req.user;
next();
});
app.use("/", imageRoutes);
app.use("/", indexRoutes);
app.listen(process.env.PORT || 5000, process.env.IP);
// app.listen(5000, function(){
// console.log('blog app has started!!');
// });