-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
62 lines (53 loc) · 1.71 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
54
55
56
57
58
59
60
61
62
const express = require('express');
const mongoose = require('mongoose');
const path = require('path');
require("dotenv").config();
const fileUpload = require('express-fileupload')
const cors = require("cors");
const app = express();
const PORT = process.env.PORT || 8080;
//DB Connection
mongoose.connect(process.env.MONGODB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true
});
mongoose.connection.on('connected', () => {
console.log('Mongoose is connected!!!!');
});
// Data parsing
app.use(cors({
credentials: true,
origin: true,
}));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.set("trust proxy", 1);
app.use(fileUpload({
useTempFiles: true
}));
//routes
const questionsRoutes = require("./routes/questionRoutes");
app.use(questionsRoutes);
const userRoutes = require("./routes/userRoutes");
app.use(userRoutes);
const uploadRoutes = require("./routes/uploadProfilePicture");
app.use('/api', uploadRoutes);
const pharmacyRoutes = require("./routes/pharmacyRoutes");
app.use(pharmacyRoutes);
const drugsRoutes = require("./routes/drugsRoutes");
app.use(drugsRoutes);
const uploadDrugRoutes = require("./routes/uploadDrugPicture");
app.use('/api', uploadDrugRoutes);
const doctorScheduleRoutes = require("./routes/doctorScheduleRoutes");
app.use(doctorScheduleRoutes);
const labelRoutes = require("./routes/labelRoutes");
app.use(labelRoutes);
if (process.env.NODE_ENV === 'production') {
app.use(express.static('client/build'));
const path = require('path');
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
}
// HTTP request logger
app.listen(PORT, console.log(`Server is starting at ${PORT}`));