-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
109 lines (82 loc) · 3.3 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
require('dotenv').config();
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const express = require('express');
const favicon = require('serve-favicon');
const hbs = require('hbs');
const mongoose = require('mongoose');
const logger = require('morgan');
const path = require('path');
const cors = require('cors');
const passport = require('passport');
const session = require('express-session');
const passportSetup = require('./config/passport');
const app = express();
// SETTING UP MONGOOSE CONNECTINO TO MONGODB
mongoose.Promise = Promise;
mongoose
.connect(process.env.MONGODB_URI, {useMongoClient: true})
.then(() => {
console.log('Connected to Mongo!')
}).catch(err => {
console.error('Error connecting to mongo', err)
});
// SETTING UP DEBUG
const app_name = require('./package.json').name;
const debug = require('debug')(`${app_name}:${path.basename(__filename).split('.')[0]}`);
// Middleware Setup
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
// Express View engine setup
app.use(require('node-sass-middleware')({
src: path.join(__dirname, 'public'),
dest: path.join(__dirname, 'public'),
sourceMap: true
}));
// SETTING UP PATH
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hbs');
app.use(express.static(path.join(__dirname, 'public')));
app.use(favicon(path.join(__dirname, 'public', 'images', 'favicon.ico')));
// SETTING UP SESSION
app.use(session({
secret: 'angular auth passport secret shh',
resave: true,
saveUninitialized: true,
cookie : { httpOnly: true, maxAge: 2419200000 }
}));
// INITIALIZING PASSPORT AND SESSION
app.use(passport.initialize());
app.use(passport.session());
passportSetup(passport);
// default value for title local
app.locals.title = 'Express - Generated with IronGenerator';
// SETTING UP CORS
app.use(cors({
credentials: true,
origin: ['http://localhost:4200', 'http://here2help.herokuapp.com/']
}));
const index = require('./routes/index');
app.use('/', index);
// ---------------------------------------------------------------------------------------------------------
// USER AUTHENTICATION + CRUD ROUTES
const usersRoutes = require('./routes/usersRoutes');
app.use('/api/users', usersRoutes);
// ---------------------------------------------------------------------------------------------------------
// ORGANIZATION CRUD ROUTES
const organizationsRoutes = require('./routes/organizationsRoutes');
app.use('/api/orgs', organizationsRoutes);
// ---------------------------------------------------------------------------------------------------------
//EVENT CRUD ROUTES
const eventsRoutes = require('./routes/eventsRoutes');
app.use('/api/events', eventsRoutes);
// ---------------------------------------------------------------------------------------------------------
// REVIEW CRUD ROUTES
const reviewsRoutes = require('./routes/reviewsRoutes');
app.use('/api/reviews', reviewsRoutes);
app.use((req,res,next)=>{ //<-- THIS LINE IS WHAT LINKS TO ALL OUR ANGULAR ROUTES ONCE WE
res.sendfile(__dirname + '/public/index.html'); // INCORPORATE THE ANGULAR APP INTO THE EXPRESS APP
});
module.exports = app;