-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
62 lines (54 loc) · 2.15 KB
/
script.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
55
56
57
58
59
60
61
62
// ------------------ Private/SECRET key configuration ------------------
require("dotenv").config();
// ------------------ Server ------------------
const express = require("express");
const cors = require("cors");
const morgan = require("morgan");
const path = require("path");
const app = express();
// ------------------ Mongodb Connection ------------------
const mongoose = require("mongoose");
// ------------------ Import Route ---------------------------
const routeUser = require("./Routes/user-route");
const routeVehicle = require("./Routes/vehicleCategory-route");
const routeParking = require("./Routes/parkingSlot-route");
const routeFloor = require("./Routes/floor-route");
const routeTransaction = require("./Routes/transaction-route");
// ------------------ Authentication Middleware ------------------
const authentication = require("./Middleware/authentication");
// ------------------------ Database connection ------------------------
const databaseURL =
process.env.NODE_ENV == "test" ? process.env.Test_DB_URL : process.env.DB_URL;
console.log(databaseURL);
mongoose.set("strictQuery", true);
mongoose
.connect(databaseURL)
.then(() => {
console.log("Database Connected successfully");
})
.catch((err) => console.log(err));
app.use("/Images", express.static(path.join(__dirname, "/Images")));
// --------------------------- Most Important ---------------------------
// To see request.
app.use(morgan("tiny"));
app.use(cors());
app.options("*", cors());
app.use(express.json());
app.use(express.urlencoded({ urlencoded: true }));
// ------------------ Routes ------------------------------------
// User Route
app.use("/user", routeUser);
app.use(authentication.verifyUser);
app.use("/vehicle", routeVehicle);
app.use("/parkingSlot", routeParking);
app.use("/floor", routeFloor);
app.use("/transaction", routeTransaction);
// --------------------------- Errors ------------------------------------
app.use((err, req, res, next) => {
res.status(500).json({ Error: err.message });
});
// --------------------------- Running Port ---------------------------
app.listen(3001, () => {
console.log("Out port is running at 3001");
});
module.exports = app;