-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
60 lines (50 loc) · 1.3 KB
/
server.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
57
58
59
60
import config from './config';
import express from 'express';
import apiRouter from './api';
import bodyParser from 'body-parser';
import mongoose from 'mongoose';
import profile from './api/profile';
import users from './api/users';
var getUrl = function(){
if (process.env.NODE_ENV == 'test') {
return process.env.MONGOLAB_URI_TEST;
} else {
return process.env.MONGOLAB_URI;
}
};
const server = express();
server.use(bodyParser.urlencoded({ extended: true }));
server.use(bodyParser.json());
server.use('/api', apiRouter);
server.use('/api/profile', profile);
server.use('/api/users', users);
server.set('view engine', 'ejs');
server.get('/', (req, res)=>{
res.render('index', {
content: 'Hello Partials!!'
});
});
server.get('/users', (req, res)=>{
res.render('index', {
content: 'Hello Partials!!'
});
});
server.get('/users/new', (req, res)=>{
res.render('index', {
content: 'Hello Partials!!'
});
});
server.use(express.static('public'));
server.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
mongoose.connect(getUrl(), function (err, db){
if (err) {
console.log('Unable to connect to the mongoDB server. Error:', err );
} else {
console.log('Connect established to', getUrl());
}
});
module.exports = server;