-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
44 lines (32 loc) · 1.18 KB
/
server.js
File metadata and controls
44 lines (32 loc) · 1.18 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
44
var express = require('express');
//var cors = require('cors'),
app = express(),
port = process.env.PORT || 88,
mongoose = require('mongoose'),
Animal = require('./api/models/animalModel'), //created model loading here
bodyParser = require('body-parser');
//var whitelist = ['http://zoobeacon.dev', 'http://zoobcn.co', 'http://localhost:88']
app.disable("etag")
//app.options('*', cors()) // include before other routes
/* var corsOptions = {
origin: function (origin, callback) {
if (whitelist.indexOf(origin) !== -1) {
callback(null, true)
} else {
callback(new Error('Not allowed by CORS'))
}
}
}
app.get('/animals/:id', cors(corsOptions), function (req, res, next) {
res.json({msg: 'This is CORS-enabled for a whitelisted domain.'})
})
*/
// mongoose instance connection url connection
mongoose.Promise = global.Promise;
mongoose.connect('mongodb://localhost/Animaldb');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
var routes = require('./api/routes/animalRoutes'); //importing route
routes(app); //register the route
app.listen(port);
console.log('zoo RESTful API server started on: ' + port);