-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
47 lines (34 loc) · 1.17 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
var express = require("express");
var app = express();
var bodyParser = require("body-parser");
var mongoose = require("mongoose");
var passport = require("passport");
var LocalStartegy = require("passport-local");
var user = require("./models/user");
var methodOverride = require("method-override");
mongoose.connect("mongodb://localhost/work");
app.use(bodyParser.urlencoded({extended: true}));
app.use(methodOverride("_method"));
app.set("view engine", "ejs");
app.use(express.static(__dirname + "/public"));
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
app.use(require("express-session")({
secret: "A@a#B$b%C^c&D*d(E)e_E+f=1,2<9>/}?\|",
resave: false,
saveUninitialized: false
}));
app.use(passport.initialize());
app.use(passport.session());
passport.use(new LocalStartegy(user.authenticate()));
passport.serializeUser(user.serializeUser());
passport.deserializeUser(user.deserializeUser());
app.use(function(req, res, next){
res.locals.currentUser = req.user;
next();
});
app.use(indexRouter);
app.use(usersRouter);
app.listen(process.env.PORT, function(){
console.log("The Server Is listening at: "+ process.env.PORT);
});