-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
55 lines (45 loc) · 1.31 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
// Basic Lib Imports
const express = require("express");
const helmet = require("helmet");
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
require("dotenv").config();
const cors = require('cors');
const { errorHandler } = require("./app/middleware/errorMiddleware");
const connectDB = require("./config/db");
connectDB();
const applicationRoutes = require('./app/routes/index');
const app = express();
app.use('/uploads', express.static(__dirname + '/uploads'));
app.use(helmet());
app.use(bodyParser.json());
app.use(cookieParser());
app.use(express.json());
app.use(cors(
{
origin: `${process.env.FRONTEND_URL}`,
credentials: true
}
));
app.use(
express.urlencoded({
extended: false,
})
);
// Routing Implement
app.use('/api/v1/', applicationRoutes);
// Health Check
app.use("/health", (req, res) => {
res.status(200).json({ status: 200, success: true, message: "Health OK🔥" });
});
// Root
app.use("/", (req, res) => {
res.status(200).json({ status: 200, success: true, message: "If you saw this, it's because our servers are working ✅." });
});
// Undefined Route Implement
app.use("*", (req, res) => {
res.status(404).json({ status: 404, success: false, message: "Not Found" });
});
// Custom error handler
app.use(errorHandler);
module.exports = app;