Skip to content

Commit 4508c38

Browse files
committed
feat: add swagger doc
1 parent 5cdafaa commit 4508c38

File tree

4 files changed

+176
-2
lines changed

4 files changed

+176
-2
lines changed

package-lock.json

Lines changed: 154 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"inquirer": "^9.2.12",
1818
"joi": "^17.11.0",
1919
"playwright": "*",
20-
"prettier": "^3.1.0"
20+
"prettier": "^3.1.0",
21+
"swagger-ui-express": "^5.0.0"
2122
},
2223
"devDependencies": {
2324
"@apify/tsconfig": "^0.1.0",
@@ -26,6 +27,8 @@
2627
"@types/express-fileupload": "^1.4.4",
2728
"@types/inquirer": "^9.0.7",
2829
"@types/node": "^20.0.0",
30+
"@types/swagger-ui-express": "^4.1.6",
31+
"swagger-autogen": "^2.23.7",
2932
"ts-node": "^10.8.0",
3033
"typescript": "^5.0.0"
3134
},

src/server.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { readFile } from 'fs/promises';
44
import { crawl, write } from "./core.js";
55
import { Config, ConfigSchema } from './config.js';
66
import { configDotenv } from 'dotenv';
7+
import swaggerUi from 'swagger-ui-express';
8+
// @ts-ignore
9+
import swaggerDocument from '../swagger-output.json' assert { type: 'json' };
710

811
configDotenv();
912

@@ -13,6 +16,7 @@ const hostname = process.env.API_HOST || 'localhost';
1316

1417
app.use(cors());
1518
app.use(express.json());
19+
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
1620

1721
// Define a POST route to accept config and run the crawler
1822
app.post('/crawl', async (req, res) => {

swagger.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import swaggerAutogen from 'swagger-autogen';
2+
3+
const doc = {
4+
info: {
5+
title: 'GPT Crawler API',
6+
description: 'GPT Crawler'
7+
},
8+
host: 'localhost:5000'
9+
};
10+
11+
const outputFile = 'swagger-output.json';
12+
const routes = ['./src/server.ts'];
13+
14+
swaggerAutogen()(outputFile, routes, doc);

0 commit comments

Comments
 (0)