-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (41 loc) · 1.21 KB
/
index.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
//
// (c) 2018 Nélson Rafael Martins All Rights Reserved
//
// Filename: index.js
//
// Import express
let express = require('express');
// Import body parser
let bodyParser = require('body-parser');
// Import Mongoose
let mongoose = require('mongoose');
// Import routes
let apiRoutes = require("./api-routes");
// Import CORS
let cors = require('cors');
// Initialize the app
let app = express();
// Configure bodyparser to handle post requests
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.use(cors());
// Connect to Mongoose and set connection variable
mongoose.connect('mongodb://localhost/linhasprod', { useNewUrlParser: true });
var db = mongoose.connection;
// Setup server port
var port = process.env.PORT || 8080;
// Send message for default URL
app.get('/', (req,res) => res.send('Hello World'));
// Use Api routes in the app
app.use('/api', apiRoutes)
//Launch app to listen to specified port
app.listen(port, function () {
console.log("Running LinhasProd on port " + port);
});
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});