-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
46 lines (39 loc) · 1.21 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
import cors from "cors";
import morgan from "morgan";
import express from "express";
import dotenv from "dotenv";
import { dbConnect } from "./config/db.config.js";
import { authRouter } from "./routes/user.js";
import { songsRouter } from "./routes/songs.js";
import { adminUserManagement } from "./routes/admin/usersManagement.js";
import { logger, httpLogStream } from "./utils/log.js";
// import { redisConnection } from "./config/redis.conect.js";
dotenv.config();
dbConnect();
// redisConnection()
const app = express();
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(morgan("combined", { stream: httpLogStream }));
// TODO: Refactor this block of code
app.use("/api", authRouter);
app.use("/api", songsRouter);
app.use("/api", adminUserManagement);
// base route, for test purposes
app.get("/", (req, res) => {
res.status(200).send({
message: "API working fine!",
});
logger.log("info", "API working fine!");
console.log("API working fine!");
});
// FIXME: Refactor this, not sure of it's use
app.use((err, req, res, next) => {
res.status(err.statusCode || 500).send({
status: "error",
message: err.message,
});
next();
});
export default app;