forked from VandyHacks/pencil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
64 lines (45 loc) · 1.78 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
// Load the dotfiles.
require('dotenv/config');
const express = require('express');
// Middleware!
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const methodOverride = require('method-override');
const morgan = require('morgan');
const Raven = require('raven');
Raven.config('https://a987cc875bda41b6a6fceb76eda529a1:[email protected]/201945').install();
const mongoose = require('mongoose');
mongoose.Promise = global.Promise;
const path = require('path');
const port = process.env.PORT || 3000;
const database = process.env.DATABASE || process.env.MONGODB_URI || 'mongodb://localhost:27017';
require('./config/settings');
require('./config/admin');
// Connect to mongodb
mongoose.connect(database);
const app = express();
// The request handler must be the first middleware on the app
app.use(Raven.requestHandler());
const logFormat = process.env.NODE_ENV === 'dev' ? 'dev' : 'combined';
app.use(morgan(logFormat));
app.use(cookieParser());
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.use(methodOverride());
app.use(express.static(path.join(__dirname, '/app/client')));
// sponsorship prospectus
app.use('/sponsorship', express.static(path.join(__dirname, 'app/sponsorship.pdf')));
// Routers =====================================================================
const apiRouter = express.Router();
require('./app/server/routes/api')(apiRouter);
app.use('/api', apiRouter);
const authRouter = express.Router();
require('./app/server/routes/auth')(authRouter);
app.use('/auth', authRouter);
require('./app/server/routes')(app);
// The error handler must be before any other error middleware
app.use(Raven.errorHandler());
app.listen(port);
console.log('App listening on port ' + port);