-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
47 lines (34 loc) · 1.09 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
const express = require('express');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const mongoose = require('mongoose');
const cors = require('cors');
const userRoutes = require('./routes/userRoutes');
const app = express();
// CORS setup
app.use(cors({ optionsSuccessStatus: 200 }));
// Mongoose setup
let mongoUri = 'mongodb+srv://jakob:[email protected]/blockchain?retryWrites=true&w=majority';
if (process.env.NODE_ENV == 'production') {
mongoUri = 'mongodb://localhost/blockchain';
}
mongoose.connect(mongoUri, function (err) {
if (err) {
throw err;
}
console.log('Successfully connected');
});
mongoose.Promise = global.Promise;
let db = mongoose.connection;
db.on('error', console.error.bind(console, 'MongoDB connecton error: '));
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(userRoutes);
app.use(function (req, res, next) {
return res.status(404).json({
error: 'Route not found'
});
});
module.exports = app;