-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
43 lines (35 loc) · 1.02 KB
/
server.js
File metadata and controls
43 lines (35 loc) · 1.02 KB
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
var express = require('express');
var mongoose = require('mongoose');
var port = process.env.PORT || 3010;
var morgan = require('morgan');
var bodyParser = require('body-parser');
var app = express();
var path = require('path');
var superhero = require('./app/routes/superhero')();
var options = {
server: {
socketOptions: {
keepAlive: 1,
connectTimeoutMS: 30000
}
},
replset: {
socketOptions: {
keepAlive: 1,
connectTimeoutMS: 30000
}
}
};
mongoose.connect('mongodb://localhost/filestack', options);
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'db connection error'));
app.use(morgan('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.text());
app.use(bodyParser.json({type: 'application/json'}));
app.use(express.static(__dirname + '/public'));
app.route('/superhero').post(superhero.post).get(superhero.getAll);
app.route('/superhero/:id').get(superhero.getOne);
app.listen(port);
console.log('listening on port ' + port);