-
Notifications
You must be signed in to change notification settings - Fork 38
/
index.js
41 lines (33 loc) · 842 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
38
39
40
41
'use strict';
const express = require('express');
const cors = require('cors');
const morgan = require('morgan');
const { PORT, CLIENT_ORIGIN } = require('./config');
const { dbConnect } = require('./db-mongoose');
// const {dbConnect} = require('./db-knex');
const app = express();
app.use(
morgan(process.env.NODE_ENV === 'production' ? 'common' : 'dev', {
skip: (req, res) => process.env.NODE_ENV === 'test'
})
);
app.use(
cors({
origin: CLIENT_ORIGIN
})
);
function runServer(port = PORT) {
const server = app
.listen(port, () => {
console.info(`App listening on port ${server.address().port}`);
})
.on('error', err => {
console.error('Express failed to start');
console.error(err);
});
}
if (require.main === module) {
dbConnect();
runServer();
}
module.exports = { app };