-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
32 lines (27 loc) · 992 Bytes
/
app.js
File metadata and controls
32 lines (27 loc) · 992 Bytes
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
var express = require("express");
var app = express();
var bodyparser = require("body-parser");
var mongoose = require("mongoose");
var countryRoute = require("./server/api/country.api.js");
// access controls----------------------------------------------
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Methods",
"GET,PUT,POST,DELETE,PATCH,OPTIONS"
);
// res.header('Access-Control-Allow-Headers', 'Content-Type','Authorization');
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept"
);
next();
});
//connectDB-----------------------------------
mongoose.connect("mongodb://localhost/countrydb");
//bparser-----------------------------
app.use(bodyparser.json());
app.use(bodyparser.urlencoded({ extended: false }));
app.use('/country', countryRoute);
app.listen(3000);
console.log("Server is running at PORT:3000");