-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (42 loc) · 1.38 KB
/
index.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
// IMPORITNG MODULES
import dotenv from "dotenv";
dotenv.config();
import express from "express";
import path from "path";
import bodyParser from "body-parser";
import cors from "cors";
// ROUTERS
import { USERROUTER } from "./routers/userRouter";
import { PARKINGSPOTROUTER } from "./routers/parkingSpotRouter";
import { VEHICLEROUTER } from "./routers/vehicleRouter";
import { IPSERVERROUTER } from "./routers/ipServerRouter";
// CUSTOM MODULES IMPORT
import { CONNECTDATABSE } from "./controllers/db/connectDatabase";
// CONNECTING TO DATABASE
CONNECTDATABSE();
// CONSTANTS
const PORT = process.env.PORT || 4000;
// INITIALIZING EXPRESS
const app = express();
// SETTING UP STATIC FILES
app.use(express.static(path.join(__dirname, "public")));
app.use("/api/img", express.static(path.join(__dirname, "public/img")));
// SETTING UP BODY PARSER
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// SETTING UP CORS
app.use(cors());
// TEST ROUTE
app.route("/api/test", (req, res) => {
console.log("Server is working!", Date.now());
return res.status(200).send("Server is working!");
});
// ROUTES
app.use("/api/user", USERROUTER);
app.use("/api/user/vehicle", VEHICLEROUTER);
app.use("/api/parkingspot", PARKINGSPOTROUTER);
app.use("/api/ipserver", IPSERVERROUTER);
// STARTING SERVER
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT} ✅`);
});