-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
61 lines (48 loc) · 1.65 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
const express = require('express');
const parser = require('body-parser');
const cors = require('cors');
const methodOverride = require('method-override');
//required for passport
const cookieParser = require('cookie-parser');
const passport = require('passport');
const flash = require('connect-flash');
const morgan = require('morgan');
const session = require('express-session');
//call in controllers
const usersController = require('./controllers/users.js');
const cheerupsController = require('./controllers/cheerups');
//instantiate express
const app = express();
//middleware configuration
app.use(morgan('dev'));
app.use(cookieParser());
const passportConfig = require('./config/passport');
app.set('view engine', 'hbs');
app.use(methodOverride('_method'));
app.use(session({ secret: 'WDI-GENERAL-ASSEMBLY-EXPRESS' }));
app.use(flash());
passportConfig(passport);
app.use(passport.initialize());
app.use(passport.session());
app.use(function(req, res, next) {
res.locals.currentUser = req.user;
next();
});
//parser interprets key-value pairs in URLs
app.use(parser.urlencoded({ extended: true }));
//configure stylesheet
app.use('/assets', express.static('public'));
//cors allows communication from all domains
//app.use(cors());
//redirect any requests to homepage
app.get('/', (req, res) => {
res.redirect('/cheerups/');
});
//hand off requests on '/users' route to users controller
app.use('/users/', usersController);
//hands off requests on '/cheerups' to cheerups controller
app.use('/cheerups/', cheerupsController);
app.set('port', process.env.PORT || 8080);
app.listen(app.get('port'), () => {
console.log(`✅ PORT: ${app.get('port')} 🌟`);
});