-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
73 lines (63 loc) · 1.89 KB
/
server.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
import express from 'express';
import dotenv from 'dotenv';
import morgan from 'morgan';
import cors from 'cors';
import bodyParser from 'body-parser';
import swaggerJsdoc from "swagger-jsdoc";
import swaggerUI from "swagger-ui-express";
import userRouter from './src/routes/users.js';
import bookRouter from './src/routes/books.js';
import indexRouter from "./src/index.js";
import authRouter from "./src/routes/jwtAuth.js";
const app = express();
app.use(bodyParser.json());
app.use(cors({
origin: '*',
methods: ['GET', 'POST', 'PUT', 'DELETE'],
allowedHeaders: ['Content-Type', 'Authorization', 'token'],
}));
const port = process.env.PORT || 3001;
dotenv.config();
app.use(morgan("dev"));
const CSS_URL = "https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/5.1.0/swagger-ui.css";
const options = {
definition: {
openapi: "3.1.0",
info: {
title: "Book Review API with Swagger",
version: "0.1.0",
description:
"MindX Book Review API for Software Testing Program",
license: {
name: "MIT",
url: "https://spdx.org/licenses/MIT.html",
},
contact: {
name: "MindX Technology School",
url: "https://mindx.vn",
email: "[email protected]",
},
},
servers: [
{
url: process.env.SWAGGER_URL,
description: "My API Documentation",
},
],
},
apis: ["src/**/*.js"],
};
const specs = swaggerJsdoc(options);
app.use(
"/api-docs",
swaggerUI.serve,
swaggerUI.setup(specs, { customCssUrl: CSS_URL })
);
app.use("/auth", authRouter);
app.use("/", indexRouter);
app.use("/api/v1/user", userRouter);
app.use("/api/v1/books", bookRouter);
app.listen(port, () => {
console.log(`Server listening on port ${port}`);
});
export default app;