-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
45 lines (35 loc) · 989 Bytes
/
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
"use strict";
const constants = require("./app/shared/constants"),
express = require("express"),
port = process.env.PORT || 9999,
mongoose = require("./mongo"),
bodyParser = require("body-parser"),
cors = require("cors");
const app = express();
// Connect to mongodb
mongoose()
.then(function() {
console.info("Database connection successful");
})
.catch(function(err) {
console.error("Database connection error", err);
});
// We use bodyParser to make request data available in req.body
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// Allow Cross Origin Resource Sharing
app.use(cors());
/*
** START: Middleware
*/
var tasksRoute = require("./app/routes/tasks.route");
tasksRoute(app);
/*
** End: Middleware
*/
// Error handling if no endpoint found
app.use(function(req, res) {
res.status(404).send({ message: `API not found. '${req.originalUrl}'` });
});
app.listen(port);
console.log(`todo api running on port ${port}`);