forked from goitacademy/nodejs-homework-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
76 lines (57 loc) · 1.98 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
import express from "express";
import cors from "cors";
import logger from "morgan";
import "dotenv/config";
import path from "path";
import swaggerUi from 'swagger-ui-express';
import swaggerJsdoc from 'swagger-jsdoc';
import authRouter from "./routes/api/auth-router.js";
import contactsRouter from "./routes/api/contacts-router.js";
import googleAuthRouter from "./routes/api/google-auth-router.js";
const app = express(); // - web-server
const formatsLogger = app.get('env') === 'development' ? 'dev' : 'short';
app.use(logger(formatsLogger));
app.use(cors());
app.use(express.json());
app.use(express.static('public'));
// Swagger options
const options = {
definition: {
openapi: '3.0.1',
info: {
title: 'My Test Swagger API',
version: '1.0.0',
description: "API documentation for project 'final-project-backend'. [Backend github repository](https://github.com/NickTsalyn/final-project-backend)",
license: {
"name": "MIT",
"url": "https://opensource.org/licenses/MIT"
}
},
servers: [
{ url: 'http://localhost:3232' }
]
},
// Paths to files with annotations
apis: ['./swagger/swagger.js', './routes/api/auth-router.js'],
};
const specs = swaggerJsdoc(options);
app.use("/lobsters/api-docs", swaggerUi.serve, swaggerUi.setup(specs));
// Swagger options
app.use("/users", authRouter);
app.use("/api/contacts/", contactsRouter);
app.use("/auth", googleAuthRouter);
// Код для перевірки авторизації з link.html
const basePath = path.resolve();
app.use(express.static(path.join(basePath, "public")));
app.get("/link", (req, res) => {
res.sendFile(path.join(basePath, "public", "link.html"));
});
// Код для перевірки авторизації з link.html
app.use((req, res) => {
res.status(404).json({ message: "Not Found" })
});
app.use((err, req, res, next) => {
const { status = 500, message = "Server error" } = err;
res.status(status).json({ message });
});
export default app;