-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (43 loc) · 1.45 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
/* import environmental variables */
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config();
}
const express = require('express'),
app = express(),
server = require('http').Server(app),
path = require('path'),
bodyParser = require('body-parser'),
mongoose = require('mongoose');
/* declare all models */
const User = require('./database/user'),
Student = require('./database/student'),
Team = require('./database/team');
if (process.env.NODE_ENV !== 'production') {
app.use(require('morgan')('dev'));
}
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(express.static(path.join(__dirname, 'public')));
app.use('/docs', express.static('public/assets/docs'));
app.use('/data', express.static('public/assets/json'));
/* start database connection */
mongoose.connect(process.env.DB_URL, {
useMongoClient: true,
promiseLibrary: require('bluebird')
});
/* route endpoints */
const authRouter = require('./routes/auth'),
userRouter = require('./routes/users'),
teamRouter = require('./routes/teams');
app.use('/', authRouter);
app.use('/api/users', userRouter);
app.use('/api/teams', teamRouter);
/* serve home page */
app.get('/*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'public/index.html'));
});
/* start http server */
server.listen(process.env.PORT, () => {
const port = server.address().port;
console.log('CMIMC running on port', port);
});