-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
43 lines (35 loc) · 1.03 KB
/
app.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
const express = require("express");
const mongoose = require("mongoose");
const cors = require("cors");
require("dotenv").config();
const caseRoutes = require("./routes/caseRoutes");
const criminalRoutes = require("./routes/criminalRoutes.js");
const evidenceRoutes = require("./routes/evidenceRoutes.js");
const timeoutMiddleware = require("./Middleware/timeout");
const app = express();
// Middleware
app.use(express.json());
app.use(timeoutMiddleware);
app.use(cors());
app.use(express.urlencoded({ extended: true }));
// Routes
app.use("/api", caseRoutes);
app.use("/api", criminalRoutes);
app.use("/api", evidenceRoutes);
app.get("/", (req, res) => {
res.send("API working");
});
// Connect to MongoDB
mongoose
.connect(process.env.MONGO_URI)
.then(() => {
console.log("Connected to MongoDB");
})
.catch((err) => {
console.error("Error connecting to MongoDB:", err.message);
});
// Start the server
const PORT = process.env.PORT || 4000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});