This repository has been archived by the owner on Mar 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.js
72 lines (64 loc) · 1.65 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
const express = require("express");
const cookieSession = require("cookie-session");
const app = express();
const authConfig = require("./src/config/auth.config");
const swaggerJsDoc = require("swagger-jsdoc");
const swaggerUi = require("swagger-ui-express");
const swaggerOptions = {
definition: {
openapi: "3.0.0",
info: {
title: "Chat app API",
version: "0.0.1",
description: "Chat app API documentation",
contact: {
name: "Jef van der Avoirt",
url: "https://github.com/JefvdA"
},
license: {
name: "MIT",
url: "https://github.com/JefvdA/Chat-app-BE/blob/main/LICENSE"
},
},
servers: [
{
url: "http://localhost:3000",
description: "Local (dev) server"
},
{
url: "https://jefvda-chat-app-api.herokuapp.com/",
description: "Heroku (prod) server"
}
]
},
apis: ["src/routes/*.js"]
}
const swaggerDocs = swaggerJsDoc(swaggerOptions);
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocs));
app.use(express.json());
app.use(
express.urlencoded({
extended: true,
})
);
app.use(
cookieSession({
name: "chat-app-session",
secret: authConfig.cookieSecret,
httpOnly: true,
})
);
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Headers", "Origin, Content-Type, Accept");
next();
});
app.get("/", (req, res) => {
res.redirect("/api-docs");
});
// Import routes
const authRouter = require("./src/routes/auth.routes");
const testRouter = require("./src/routes/test.routes");
// Use routes
app.use("/api/auth", authRouter);
app.use("/api/test", testRouter);
module.exports = app;