-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.js
43 lines (34 loc) · 1.15 KB
/
app.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
var express = require('express');
var path = require('path');
var bodyParser = require('body-parser');
var fs = require("fs");
var app = express();
var mongoose = require("mongoose");
//connect to mongodb
mongoose.connect("mongodb://localhost/fligth_reservation313");
//register models
fs.readdirSync(path.join(__dirname,"models")).forEach(function (filename) {
require("./models/"+filename);
});
app.use((req,resp,next)=>{
resp.header("Access-Control-Allow-Origin","*");
resp.header("Access-Control-Allow-Headers","Content-Type,x-access-token");
resp.header("Access-Control-Allow-Methods","GET,POST");
next();
});
app.use((req,res,next)=>{
res.header("Access-Control-Allow-Origin","*");
res.header("Access-Control-Allow-Headers","Content-Type,x-access-token");
res.header("Access-Control-Allow-Methods","GET,POST,PUT,DELETE")
next();
});
//add body-parser middleware
app.use(bodyParser.json());
var reservation = require('./controllers/reservation');
app.use('/reservation',reservation);
var seat = require('./controllers/seat');
app.use('/seat',seat);
//start listenning
app.listen(9090,function(){
console.log("Starting....")
});