-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
48 lines (38 loc) · 1.26 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
const express = require("express");
const app = express();
const cors = require("cors")
const path = require('path');
const { connection } = require("./config/db.js");
const { appointmentRoute } = require('./routes/appointment.route.js');
const { UserRouter } = require("./routes/user.route.js");
const { doctorRoute } = require("./routes/doctor.route.js");
const { authentication } = require("./middleware/authentication.js");
require('dotenv').config();
//Middlewares
app.use(express.json());
app.use(cors());
// app.use("/appointments", authentication);
// app.use("/doctors", authentication);
//Routes
app.use("/user", UserRouter);
app.use("/appointments", appointmentRoute);
app.use("/doctors", doctorRoute);
app.get("/home", (req, res) => {
res.send("Api Working fine");
});
app.get("/", (req, res) => {
app.use(express.static(path.join(__dirname, "client", "dist")));
res.sendFile(path.resolve(__dirname, "client", "dist", "index.html"));
});
app.listen(process.env.port || 1337 || 8080, async () => {
try {
await connection;
console.log("Connected To DB");
} catch (error) {
console.log(
"Something went wrong while connecting to the Mongo DataBase " +
error.message
);
}
console.log(`listening on port ${process.env.port}`);
});