Skip to content

Commit

Permalink
express docs fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Piootrekk committed Dec 7, 2024
1 parent 8919ece commit 605273f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
15 changes: 7 additions & 8 deletions express-proxy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ const app = express();
const port = 3001;
const swaggerDocument = YAML.load("./swagger-definition.yaml");

app.listen(port, () => console.log(`Server listening on port ${port}`));

app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.use("/docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use((req, res, next) => {
Expand All @@ -18,7 +16,11 @@ app.use((req, res, next) => {
});

app.get("/", (req, res) => {
res.redirect("/api-docs");
res.redirect("/docs");
});

app.get("/health", (req, res) => {
res.json({ health: true });
});

app.get("/link/:path(*)", async (req, res) => {
Expand Down Expand Up @@ -99,7 +101,4 @@ app.delete("/link/:path(*)", async (req, res) => {
}
});

app.post("/test", (req, res) => {
console.log(req.body);
res.json(req.body);
});
app.listen(port, () => console.log(`Server listening on port ${port}`));
36 changes: 24 additions & 12 deletions express-proxy/swagger-definition.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
openapi: 3.0.0
info:
title: "Express API Proxy with Swagger "
title: "Express API Proxy with Swagger"
version: "1.0.0"
description: "A simple Express API proxy with Swagger documentation to avoid CORS policy errors and redirect to the correct url"
apis:
- "./index.js"
description: "A simple Express API proxy with Swagger documentation to avoid CORS policy errors and redirect to the correct URL"
paths:
/link/{path}:
get:
summary: Get request with url path
summary: Get request with URL path
tags: [Url proxy]
description: Normal or encoded url path
description: Normal or encoded URL path
parameters:
- in: path
name: path
Expand All @@ -30,9 +28,8 @@ paths:
description: OK
500:
description: Error
/link/{path}:
post:
summary: Post request with url path
summary: Post request with URL path
tags: [Url proxy]
description: Normal or encoded path
parameters:
Expand All @@ -41,6 +38,7 @@ paths:
schema:
type: string
required: true
description: URL path
examples:
example:
value: "https://jsonplaceholder.typicode.com/posts"
Expand All @@ -56,9 +54,8 @@ paths:
description: OK
500:
description: Error
/link/{path}:
put:
summary: Put request with url path
summary: Put request with URL path
tags: [Url proxy]
description: Normal or encoded path
parameters:
Expand All @@ -67,6 +64,7 @@ paths:
schema:
type: string
required: true
description: URL path
examples:
example:
value: "https://jsonplaceholder.typicode.com/posts/1"
Expand All @@ -83,9 +81,8 @@ paths:
description: OK
500:
description: Error
/link/{path}:
delete:
summary: Delete request with url path
summary: Delete request with URL path
tags: [Url proxy]
description: Normal or encoded path
parameters:
Expand All @@ -94,6 +91,7 @@ paths:
schema:
type: string
required: true
description: URL path
examples:
example:
value: "https://jsonplaceholder.typicode.com/posts/1"
Expand All @@ -102,3 +100,17 @@ paths:
description: OK
500:
description: Error
/health:
get:
summary: Health check
tags: [Health]
description: Health check endpoint
responses:
200:
description: OK
content:
application/json:
example:
health: true
500:
description: Error

0 comments on commit 605273f

Please sign in to comment.