forked from LapshinIV/RestAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
28 lines (23 loc) · 921 Bytes
/
server.js
File metadata and controls
28 lines (23 loc) · 921 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
var express = require('express'); // call express
var app = express(); // define our app using express
var flights = require('./db/Flights_Full.json');
var port = process.env.PORT || 8080; // set our port
var _ = require("underscore");
var cors = require('cors');
app.use(cors());
app.get('/carriers', function(req, res) {
res.send('Not supported yet. Coming soon...\n');
});
app.get('/flight_subscriptions/:carrier_code', function(req, res) {
var flights2 = _.filter(flights, function(flight){ return flight.carrier_code === req.params.carrier_code; });
if(flights2.length > 0) {
res.json(flights2);
}else{
res.send('Page not Found\n', 404);
}
});
app.get('*', function(req, res){
res.send('Page not Found\n', 404);
});
app.listen(port); // START THE SERVER
console.log('Magic happens on port ' + port);