-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
71 lines (54 loc) · 1.64 KB
/
index.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
require('dotenv').config();
var db = require('./models');
var express = require('express');
var ejsLayouts = require('express-ejs-layouts');
var bodyParser = require('body-parser');
var session = require('express-session');
var passport = require('./config/ppConfig');
var flash = require('connect-flash');
var isLoggedIn = require('./middleware/isLoggedIn');
var path = require('path');
var app = express();
app.set('view engine', 'ejs');
app.use(require('morgan')('dev'));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(ejsLayouts);
app.use(express.static(path.join(__dirname + '/public/')));
app.use(session({
secret: process.env.SESSION_SECRET || 'supersecretpassword',
resave: false,
saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
app.use(function(req, res, next) {
res.locals.alerts = req.flash();
res.locals.currentUser = req.user;
next();
});
app.get('/', function(req, res) {
res.render('index');
});
app.get('/profile', isLoggedIn, function(req, res) {
db.user.find({
where: {
id: req.user.id
},
include: [db.car]
}).then(function(user){
res.render('profile',{user:user});
});
});
app.use('/auth', require('./controllers/auth'));
app.use('/profile', require('./controllers/profile'));
app.use('/log', require('./controllers/log'));
//api test repsonses
app.get('/year', function(req,res){
res.sendFile(__dirname+ "/carYearSample.json");
});
app.get('/style', function(req,res){
res.sendFile(__dirname+ "/carStyleSample.json");
});
var server = app.listen(process.env.PORT || 3000);
module.exports = server;