-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
52 lines (41 loc) · 1.33 KB
/
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
45
46
47
48
49
50
51
52
//SPDX-License-Identifier: Apache-2.0
// nodejs server setup
// call the packages we need
var express = require('express'); // call express
var app = express(); // define our app using express
var bodyParser = require('body-parser');
var path = require('path');
// Load all of our middleware
// configure app to use bodyParser()
// this will let us get the data from a POST
// app.use(express.static(__dirname + '/client'));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// instantiate the app
var app = express();
//SPDX-License-Identifier: Apache-2.0
var car = require('./controller.js');
app.get('/', function(req, res) {
res.json({message: 'App is running!', status: 200});
});
app.get('/test', function(req, res) {
res.sendFile(__dirname + '/views/index.html')
});
app.get('/get_car/:id', function(req, res){
car.get_car(req, res);
});
app.get('/add_car/:car', function(req, res){
car.add_car(req, res);
});
app.get('/get_all_cars', function(req, res){
car.get_all_cars(req, res);
});
app.get('/change_owner/:owner', function(req, res){
car.change_owner(req, res);
});
// Save our port
var port = process.env.PORT || 8000;
// Start the server and listen on port
app.listen(port,function(){
console.log("Live on port: " + port);
});