forked from Codehackerone/Medify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
49 lines (40 loc) · 1.15 KB
/
app.ts
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
import express from "express";
import cors from "cors";
import { config } from "dotenv";
import { message } from "./helpers/message";
import { OK, NOT_FOUND } from "./helpers/messageTypes";
import mongoose from "mongoose";
import userRouter from "./users/users.route";
import routineRouter from "./routines/routine.route";
config();
const app = express();
const PORT = process.env.PORT;
const MONGODB_URI: any = String(process.env.MONGO_URI);
const connectOptions: any = {
useNewUrlParser: true,
useUnifiedTopology: true,
};
try {
mongoose.connect(MONGODB_URI, connectOptions);
} catch (err) {
console.log(err);
}
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
mongoose.connection.once("open", () => {
console.log("MongoDB connected");
});
app.get("/", (req: any, res: any) => {
message(res, OK, "Welcome to Medify API");
});
app.use("/api/users", userRouter);
app.use("/api/routines", routineRouter);
app.all("*", (req: any, res: any) => {
message(res, NOT_FOUND, "Route does not exist");
});
app.listen(PORT, () => {
console.log(
`Medify Server listening on ${PORT}. URL:http://localhost:${PORT}`
);
});