forked from evanplaice/ossu-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (27 loc) · 783 Bytes
/
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
'use strict';
// load env variables
require('dotenv').load();
// load deps
let express = require('express');
let Api = require('./api');
let mongoose = require('mongoose');
let fs = require('fs');
// load the app
let app = express();
let db;
// connect to the db
mongoose.connect(process.env.NODE_ENV === 'test' ? process.env.MONGO_TEST_URI : process.env.MONGO_URI);
db = mongoose.connection;
app.set('db', db);
// compile models
fs.readdirSync('./models/').forEach((file) => {
require('./models/' + file)();
});
// mount the api router
app.use('/api', Api(app));
// TODO: mount an auth router
// db.once('open', onDatabaseConnection);
module.exports = app;
app.listen(process.env.PORT || 8080, () => {
console.log('Server listening on port', process.env.PORT);
});