-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
29 lines (25 loc) · 751 Bytes
/
Copy pathserver.js
File metadata and controls
29 lines (25 loc) · 751 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
const express = require('express');
const cors = require('cors');
const port = '8080';
const app = express();
const seatData = require('./seatData.js');
app.options('*', cors());
app.use(cors());
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.options(`*`, cors());
app.get("/seatData", (req, res) => {
if (req.param('seatNumber')) {
const seatNumber = req.param('seatNumber');
const seat = seatData.seats.find( (item) => item.seatNumber === seatNumber )
res.status(200).json(seat);
} else {
res.status(200).json(seatData);
}
})
/**
* Start the server to listen on port 8080
*/
app.listen(port, function () {
console.log("Server is running on " + port + " port");
});