-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
59 lines (51 loc) · 1.39 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
48
49
50
51
52
53
54
55
56
57
58
59
const express = require("express");
const cors = require("cors");
const morgan = require("morgan");
const createError = require("http-errors");
const compression = require("compression");
const cookieParser = require("cookie-parser");
const { PORT } = require("./Config");
const app = express();
// Database Connection
require("./Config/DatabaseConfigrations");
// Middlewares
app.use(
cors({
origin: "*",
methods: "GET,POST,PATCH,PUT,DELETE",
credentials: true,
"Access-Control-Allow-Credentials": true,
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "*",
})
);
app.use(morgan("dev"));
app.use(compression());
app.use(cookieParser());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(express.static("Public"));
// Routes
app.get("/", async (req, res, next) => {
res.status(200).send({
status: 1,
message: "🎉 Congratulations! Your Server Works Perfectly! 🎉",
});
});
// Routes
app.use("/api", require("./Routes/Auth.Routes"));
app.use("/api", require("./Routes/Bill.Routes"));
// Error Handling
app.use(async (req, res, next) => {
next(createError.NotFound());
});
app.use((err, req, res, next) => {
res.status(err.status || 500);
res.send({
status: 0,
message: err.message,
});
});
app.listen(PORT, () => {
console.log(`🎉 Server Up & Running... On PORT http://localhost:${PORT} 🎉`);
});