-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
47 lines (40 loc) · 1.24 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
require("dotenv").config();
const express = require("express");
const mongoose = require("mongoose");
const cors = require("cors");
const authRouter = require("./routes/authRoutes");
const userRouter = require("./routes/userRoutes");
const walletRouter = require("./routes/walletRoutes");
const transRouter = require("./routes/transactionRoutes");
const { errorHandler } = require("./middlewares/errors");
const { MONGO_DB, PORT } = process.env;
const app = express();
const APP_PORT = PORT || 8080;
mongoose.connect(MONGO_DB);
const database = mongoose.connection;
database.on("error", (error) => {
console.log(error);
});
database.once("connected", () => {
console.log("Database Connected");
});
app.listen(APP_PORT, () => {
console.log(`Server is listening on port ${APP_PORT}`);
});
app.use(
cors({
origin: ["http://localhost:3000"],
methods: ["GET", "POST", "PATCH", "PUT", "DELETE"],
credentials: true,
})
);
app.get("/", (req, res) => {
res.send("<h1>Healthy</h1>");
});
app.use(errorHandler);
app.use(express.json({ limit: "20mb" }));
app.use(express.urlencoded({ limit: "20mb", extended: true }));
app.use("/api/auth", authRouter);
app.use("/api/user", userRouter);
app.use("/api/wallet", walletRouter);
app.use("/api/transaction", transRouter);