-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
37 lines (32 loc) · 1.1 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
const apiPort = process.env.PORT || 8080;
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
const {queryCar, changeCarOwner, createCar, queryAllCars} = require("./jeff");
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader(
"Access-Control-Allow-Methods",
"GET,POST,OPTIONS,PUT,PATCH,DELETE"
);
res.setHeader(
"Access-Control-Allow-Headers",
"X-Requested-With,Content-type,Authorization"
);
res.setHeader("Access-Control-Allow-Credentials", true);
next();
});
// app.use(express.static("../landing-page/public"));
app.enable("trust proxy");
app.get("/", (req, res)=> {
res.sendStatus(200);
})
app.get("/queryCar/:numId", queryCar);
app.get("/queryAllCars", queryAllCars);
app.post("/createCar/:numId", createCar);
app.post("/changeCarOwner/:numId/:charge/:jailtime/:date", changeCarOwner);
app.listen(apiPort, () => {
console.log(`Server is running at port ${apiPort}`);
});