Skip to content

Commit

Permalink
implement swagger apis page (#17)
Browse files Browse the repository at this point in the history
* remove get doc.html

Signed-off-by: cbh778899 <[email protected]>

* implement swagger api page

Signed-off-by: cbh778899 <[email protected]>

* add babel plugin

Signed-off-by: cbh778899 <[email protected]>

* fix dev compose build issue

Signed-off-by: cbh778899 <[email protected]>

* add new dependencies

Signed-off-by: cbh778899 <[email protected]>

---------

Signed-off-by: cbh778899 <[email protected]>
  • Loading branch information
cbh778899 authored Aug 2, 2024
1 parent c31ef8a commit 0e4f8db
Show file tree
Hide file tree
Showing 7 changed files with 428 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ compose-build-dev: env model-prepare
@docker compose -f docker-compose-dev.yaml build

.PHONY: dev
dev: env model-prepare
dev: compose-build-dev
@docker compose -f docker-compose-dev.yaml up -d

# stop
Expand Down
6 changes: 5 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import globals from "globals/index.js";
import pluginJs from "@eslint/js";
import * as babelParser from "@babel/eslint-parser"
import babelImportAttributesPlugin from '@babel/plugin-syntax-import-attributes'


export default [
Expand All @@ -14,9 +15,12 @@ export default [
babelOptions: {
babelrc: false,
configFile: false,
plugins: [
babelImportAttributesPlugin
]
}
}
}
}
},
{
ignores: ["volumes/*"],
Expand Down
14 changes: 11 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,26 @@ import { configDotenv } from 'dotenv';
import buildRoutes from './routes/index.js'

import swStats from 'swagger-stats';
import * as swaggerUi from 'swagger-ui-express'
import swaggerSpec from "./swagger.json" with { type: "json" };

configDotenv()

const app = express();
app.use(cors());
app.use(bodyParser.json());

buildRoutes(app);

// swagger setup
app.use(swStats.getMiddleware({
name: "Voyager Swagger Monitor",
uriPath: '/stats'
uriPath: '/stats',
swaggerSpec
}))
app.use('/', swaggerUi.serve, swaggerUi.setup(swaggerSpec, {
customSiteTitle: "Voyager APIs"
}))

buildRoutes(app);

const PORT = process.env.PORT || 8000
app.listen(PORT, '0.0.0.0', () => {
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"description": "OpenAI like APIs",
"main": "index.js",
"scripts": {
"start": "node index.js",
"dev": "nodemon index.js",
"start": "node index.js --disable-warning=ExperimentalWarning",
"dev": "nodemon index.js --disable-warning=ExperimentalWarning",
"lint": "npx eslint .",
"build": "npm install && node index.js"
},
Expand All @@ -15,6 +15,7 @@
"license": "ISC",
"dependencies": {
"@babel/eslint-parser": "^7.25.1",
"@babel/plugin-syntax-import-attributes": "^7.24.7",
"@eslint/js": "^9.8.0",
"body-parser": "^1.20.2",
"cors": "^2.8.5",
Expand All @@ -23,6 +24,7 @@
"express": "^4.19.2",
"globals": "^15.8.0",
"prom-client": "12",
"swagger-stats": "^0.99.7"
"swagger-stats": "^0.99.7",
"swagger-ui-express": "^5.0.1"
}
}
39 changes: 39 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ import decoderRoute from "./decoder.js";
function indexRoute() {
const router = Router();

router.get('/', (_, res)=>{
res.sendFile(`${process.cwd()}/doc.html`);
})

router.get('/healthy', (_, res)=>{
res.status(200).send('ok')
})
Expand Down
Loading

0 comments on commit 0e4f8db

Please sign in to comment.