-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
67 lines (50 loc) · 1.76 KB
/
server.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
// Dependencies
const express = require('express');
const expressLayouts = require('express-ejs-layouts');
const passport = require('passport');
const flash = require('connect-flash');
const session = require('express-session');
const ejs = require('ejs')
// USE INDEX.EJS
const db = require('./models');
const router = require('./controllers/recipeController');
const app = express();
// PASSPORT CONFIG
require('./config/passport')(passport);
const PORT = process.env.PORT || 8080;
// Statis directory
app.use(express.static("public"));
// BODYPARSER
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
//Import routes and give the sever access to them NEEDED????
var routes = require("./controllers/recipeController.js")
app.use(routes);
// EJS
app.use(expressLayouts);
app.set('view engine', 'ejs');
// FOR PASSPORT USING EXPRESS SESSION
app.use(session({ secret: 'keyboard cat', resave: true, saveUninitialized: true })); // session secret
// PASSPORT MIDDLEWARE
app.use(passport.initialize());
app.use(passport.session()); // for persistent login
// CONNECT FLASH
app.use(flash());
// GLOBAL VARS
// app.use((err, req, res, next) => {
// res.locals.success_msg = req.flash('success_msg');
// res.locals.error_msg = req.flash('error_msg');
// res.locals.error = req.flash('error');
// console.log(err);
// next();
// });
// ROUTES
app.use('/users', require('./controllers/users.js'));
// Import routes and give the sever access to them NEEDED????
var routes = require("./controllers/recipeController.js");
app.use(routes);
db.sequelize.sync().then(function () {
app.listen(PORT, console.log(`Server started on port ${PORT}`));
}).catch(function (err) {
console.log(err, "Something went wrong updating the Database");
});