-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
29 lines (23 loc) · 904 Bytes
/
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
const express = require('express');
const mongoose = require('mongoose');
const cors = require('cors');
const path = require('path');
const logger = require('winston');
const userController = require('./controllers/users');
const app = express();
// Add middleware
app.use(cors());
app.use(express.static(path.join(__dirname, 'public')));
// See the User Controller for `/users` routes
app.use('/users', userController);
// Some switches for acceptance tests
if (require.main === module) {
// Only connect to MongoDB if app.js is run
// If require'd (e.g. in tests), let these tests establish a DB connection themselves
mongoose.connect('mongodb://localhost/users');
// Only listen when app.js is run - acceptance tests will listen on another port
app.listen(8000, function () {
logger.info('Listening at http://localhost:8000 - see here for API docs');
});
}
module.exports = app;