forked from manoelteixeira/m-cubed-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
88 lines (81 loc) · 2.57 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// app.js
/* Dependencies */
const colors = require("colors");
const express = require("express");
const cors = require("cors");
const morgan = require("morgan");
const swaggerJsdoc = require("swagger-jsdoc");
const swaggerUi = require("swagger-ui-express");
const loginController = require("./src/controllers/loginController");
const borrowersController = require("./src/controllers/borrowersController");
const lendersController = require("./src/controllers/lendersController");
const matchMessageController = require("./src/controllers/matchMessagesController");
const mailListController = require("./src/controllers/mailListController");
/* Configuration */
const swaggerOptions = {
definition: {
openapi: "3.1.0",
info: {
title: "M-Cubed API",
description: "M-Cubed API Documentation",
contact: {
name: "Team 5",
},
},
servers: [
{
description: "localhost",
url: "http://localhost:4001",
},
{
description: "m-cubed",
url: "https://m-cubed-backend.onrender.com",
},
],
},
// apis: ["./src/controllers/*.js"],
apis: [
"./src/controllers/loginController.js",
"./src/controllers/borrowersController.js",
"./src/controllers/borrowersRequestsController.js",
"./src/controllers/borrowersRequestProposalsController.js",
"./src/controllers/lendersController.js",
"./src/controllers/lendersProposalsController.js",
"./src/controllers/lendersRequestsController.js",
"./src/controllers/matchMessagesController.js",
"./src/controllers/mailListController.js",
],
};
const swaggerSpecs = swaggerJsdoc(swaggerOptions);
const app = express();
// Middleware
app.use(cors());
app.use(express.json());
// app.use(morgan("tiny"));
app.use(
morgan(function (tokens, req, res) {
return [
colors.red(tokens.method(req, res)),
colors.blue(tokens.url(req, res)),
colors.yellow(tokens.status(req, res)),
colors.magenta(tokens.res(req, res, "content-length")),
"-",
colors.green(tokens["response-time"](req, res)),
colors.green("ms"),
].join(" ");
})
);
app.use("/docs", swaggerUi.serve, swaggerUi.setup(swaggerSpecs));
app.use("/login", loginController);
app.use("/borrowers", borrowersController);
app.use("/lenders", lendersController);
app.use("/messages", matchMessageController);
app.use("/mail-list", mailListController);
app.get("/", (req, res) => {
res.status(200).json({ index: "Money Money Money." });
});
app.get("*", (req, res) => {
res.status(404).send({ error: "Not Found!" });
});
/* Export */
module.exports = app;