Skip to content

Commit

Permalink
fix(docs): tweak swagger so it can shows in vercel
Browse files Browse the repository at this point in the history
  • Loading branch information
zulfikarrosadi committed Nov 21, 2024
1 parent 5faa8d7 commit b520299
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
10 changes: 5 additions & 5 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"nodemailer": "^6.9.15",
"pino": "^9.5.0",
"pino-http": "^10.3.0",
"swagger-ui-express": "^5.0.1",
"swagger-ui-express": "^4.6.3",
"xss-filters": "^1.2.7",
"zod": "^3.23.8"
},
Expand Down
13 changes: 12 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const app = express()
import swaggerDocument from './openapi.json'
import routes from './routes'

const SWAGGER_CSS_URL =
'https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.1.0/swagger-ui.min.css'

const port = process.env.SERVER_PORT

BigInt.prototype.toJSON = function () {
Expand All @@ -18,7 +21,15 @@ app.use(cors())
app.use(express.json())
app.use(cookieParser())
app.use(sanitizeInput)
app.use('/api/docs', swaggerUI.serve, swaggerUI.setup(swaggerDocument))
app.use(
'/api/docs',
swaggerUI.serve,
swaggerUI.setup(swaggerDocument, {
customCssUrl: SWAGGER_CSS_URL,
customCss:
'.swagger-ui .opblock .opblock-summary-path-description-wrapper { align-items: center; display: flex; flex-wrap: wrap; gap: 0 10px; padding: 0 10px; width: 100%; }',
}),
)
app.use('/api/', routes)
app.listen(port, () => {
console.info(`Server running at port ${port}`)
Expand Down

0 comments on commit b520299

Please # to comment.