This commit is contained in:
@@ -4,17 +4,18 @@ import { itemsRouter } from './routes/items.js'
|
||||
import { setupSwagger } from './swagger.js'
|
||||
|
||||
const app = express()
|
||||
const prefix = process.env.PATH_PREFIX ?? ''
|
||||
|
||||
app.use(cors({ origin: 'http://localhost:3000' }))
|
||||
app.use(express.json())
|
||||
|
||||
setupSwagger(app)
|
||||
app.use('/api/items', itemsRouter)
|
||||
setupSwagger(app, prefix)
|
||||
app.use(`${prefix}/api/items`, itemsRouter)
|
||||
|
||||
const PORT = 1337
|
||||
app.listen(PORT, () => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`Server running on http://localhost:${PORT}`)
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`Swagger UI: http://localhost:${PORT}/docs`)
|
||||
console.log(`Swagger UI: http://localhost:${PORT}${prefix}/docs`)
|
||||
})
|
||||
|
||||
@@ -17,7 +17,7 @@ const options: swaggerJsdoc.Options = {
|
||||
|
||||
const spec = swaggerJsdoc(options)
|
||||
|
||||
export function setupSwagger(app: Express): void {
|
||||
app.get('/docs/json', (_req, res) => res.json(spec))
|
||||
app.use('/docs', swaggerUi.serve, swaggerUi.setup(spec))
|
||||
export function setupSwagger(app: Express, prefix = ''): void {
|
||||
app.get(`${prefix}/docs/json`, (_req, res) => res.json(spec))
|
||||
app.use(`${prefix}/docs`, swaggerUi.serve, swaggerUi.setup(spec))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user