-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
65 lines (54 loc) · 2.06 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
55
56
57
58
59
60
61
62
63
64
65
const inspectorRoutes = require("./routes/inspectorRoutes");
const patientRoutes = require("./routes/patientRoutes");
const doctorRoutes = require("./routes/doctorRoutes");
const userRoutes = require("./routes/userRoutes");
const connectDB = require('./config/db');
const bodyParser = require("body-parser");
const express = require("express");
const config = require("config");
const cors = require("cors");
const app = express();
connectDB();
//this code provide memory for save user images in database
app.use(bodyParser.json({ limit: "7mb" }));
app.use(bodyParser.urlencoded({ limit: "7mb", extended: true, parameterLimit: 7000 }));
// list of allowed origins that currently contains URLs and Regexp entries
var allowedOrigins = [config.get("FRONTEND_PRODUCTION"), config.get("FRONTEND_DEVELOPMENT"), config.get("FRONTEND_LOCAL")];
app.use(
cors({
origin: function (origin, callback) {
// allow requests with no origin
if (!origin) return callback(null, true);
for (var i = 0; i < allowedOrigins.length; i++) {
var allowedOrigin = allowedOrigins[i];
// if origin matches an allowed origin, allow the request
if (typeof allowedOrigin === "string" && allowedOrigin == origin) {
return callback(null, true);
} else if (
allowedOrigin instanceof RegExp &&
allowedOrigin.test(origin)
) {
return callback(null, true);
}
}
// if origin is not allowed
var message =
"The CORS policy for this site does not " +
"allow access from the specified Origin.";
return callback(new Error(message), false);
},
credentials: true,
})
);
app.use(express.json());
app.use("/api/users" , userRoutes);
app.use("/api/doctors" , doctorRoutes);
app.use("/api/patients" , patientRoutes);
app.use("/api/inspectors" , inspectorRoutes);
const port = config.get("PORT") || 6678;
app.get("/", (req, res) => {
res.status(200).send("Hello server is running").end();
});
app.listen(port, () => {
console.log(`Server started and listening onn port: ${port}`);
});