-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
54 lines (45 loc) · 1.67 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
53
54
const express = require("express");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const cors = require("cors");
// const authRoutes = require('./routes/authRoutes');
// const BookingHistory = require('./routes/Reservations');
// const movieBookingRoutes = require("./routes/MovieBooking");
require("dotenv").config();
const app = express();
// app.use(bodyParser.urlencoded()); // x-www-form-urlencoded <form>
app.use(bodyParser.json()); // application/json
app.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader(
"Access-Control-Allow-Methods",
"OPTIONS, GET, POST, PUT, PATCH, DELETE"
);
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
next();
});
// app.use('/api/auth', authRoutes);
// app.use("/api/cart", movieBookingRoutes);
// app.use('/api/reservations', BookingHistory)
app.use((error, req, res, next) => {
console.log(error);
const status = error.statusCode || 500;
const message = error.message;
const data = error.data;
res.status(status).json({ message: message, data: data });
});
// Route files
const fuelStations = require("./routes/FuelStationRouter");
const fuelQueues = require("./routes/FuelQueueRouter");
const fuelStatus = require("./routes/FuelStatusRouter");
// Mount routers
app.use("/api/v1/fuelStations", fuelStations);
app.use("/api/v1/fuelQueues", fuelQueues);
app.use("/api/v1/fuelStatus", fuelStatus);
mongoose
.connect(process.env.CONNECTION_URL)
.then((result) => {
const server = app.listen(process.env.PORT || 4001);
console.log(`Server started on port ${server.address().port}`);
})
.catch((err) => console.log(err));