-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
56 lines (45 loc) · 1.34 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
const express = require('express');
const morgan = require('morgan');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const cors = require('cors');
const cookieParser = require('cookie-parser');
mongoose.Promise = global.Promise;
const conn = `mongodb://${process.env.MONGO_HOST}/${process.env.MONGO_DATABASE}?replicaSet=Cluster0-shard-0`;
mongoose.connect(conn, {
useNewUrlParser: true,
keepAlive: 1,
reconnectTries: Number.MAX_VALUE,
w: "majority",
wtimeout: 10000,
ssl: true,
"auth": {"authSource": "admin"},
user: process.env.MONGO_USER,
pass: process.env.MONGO_PASSWORD,
// server: { poolSize: 5 },
// replset: {rs_name: 'Cluster0-shard-0'},
})
.then(() => {
})
.catch(err => {
console.log(err);
});
const app = express();
app.use(cookieParser());
// app.use(cors({
// origin: 'http://localhost:3000',
// credentials: true
// }));
// Middlewares moved morgan into if for clear tests
if (!process.env.NODE_ENV === 'test') {
app.use(morgan('dev'));
}
app.use(bodyParser.json());
app.get('/test', (req, res) => res.send('Welcome To Code Handbook!'))
// Routes
app.use('/users', require('./routes/users'));
const port = process.env.PORT || 8080;
app.listen(port);
console.log(`Server listening at ${port}`);
console.log(`connect api : http://localhost:${port}/`);
module.exports = app;