forked from favourori/PatientsRegistryAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
83 lines (66 loc) · 1.84 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* eslint-disable no-console */
const express = require("express");
const app = express();
const mongoose = require("mongoose");
const cors = require("cors");
require("dotenv").config();
// import patients routes
const patientRoute = require("./route/patient");
const userRoute = require("./route/users");
const adminRoute = require("./route/admin");
const registryRoute = require("./route/registry");
// import disease routes
const diseaseRoute = require("./route/disease");
// import group routes
const groupRoute = require("./route/group");
// setup body parser
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(cors());
// allowing cors
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "*");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept"
);
next();
});
(async () => {
try {
const options = {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true,
autoIndex: false
};
await mongoose.connect(process.env.DB_URL, options);
console.log("connected to DB");
} catch (err) {
console.log(err.toString());
}
})();
app.get("/", (req, res) => {
res.status(200).send({
message: "Server Up"
});
});
// Auth route
app.use("/api/v1/users", userRoute);
// Patients Routes
app.use("/api/v1/patients", patientRoute);
// Disease Routes
app.use("/api/v1/diseases", diseaseRoute);
// admin and researcher route
app.use("/api/v1/admins", adminRoute);
// group route
app.use("/api/v1/groups", groupRoute);
// registry route
app.use("/api/v1/registry", registryRoute);
// Spin up dev server
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});