forked from systers/PC-Prep-Kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
98 lines (82 loc) · 2.75 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
// Get dependencies
const express = require('express');
const path = require('path');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const http = require('http');
const passport = require('passport');
const flash = require('connect-flash');
const session = require('express-session');
const async = require('async');
const nodemailer = require('nodemailer');
const crypto = require('crypto');
const winston = require('winston');
// Logger configuration
winston.add(
winston.transports.File, {
filename: 'logs/pcprepkit.log',
level: 'info',
json: true,
eol: '\n', // for Windows, or `eol: ‘n’,` for *NIX OSs
timestamp: true
}
);
// Database configuration
// Models
const models = require('./database/models');
// Sync Database
models.sequelize.sync().then(function() {
winston.info('Nice! Database looks fine')
}).catch(function(err) {
winston.error(err, 'Something went wrong with the Database Update!')
});
const associations = require('./database/associations')(models);
const app = express();
// Get our API routes
const api = require('./routes/api');
// test api route
const test = require('./routes/test');
// route for verification and registration
const verification = require('./routes/verification');
const registration = require('./routes/registration');
// uncomment after placing your favicon in /public
//const favicon = require('serve-favicon');
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'dist')));
app.use(session({
secret: 'PC Prep Kit Secret',
saveUninitialized: true,
resave: true
}));
// passport and persistent session initialization
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
app.use(flash()); // use connect-flash for flash messages stored in session
// Set up passport configurations
const passportSetup = require('./config/passport')(passport, models);
// Set test routes
app.use('/test', test);
// Set api routes
app.use('/api', api);
app.use('/registration', registration);
app.use('/verification', verification);
// Set authentication routes
const auth = express.Router();
require('./routes/auth.js')(auth, passport, async, nodemailer, crypto, models);
app.use('/auth', auth);
// Set other routes
const index = express.Router();
require('./routes/index.js')(index, passport, path);
app.use('/', index);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
const err = new Error('Not Found');
err.status = 404;
next(err);
});
module.exports = app;