This commit is contained in:
@@ -35,6 +35,7 @@ jobs:
|
|||||||
docker run -d \
|
docker run -d \
|
||||||
--name tmc-backend \
|
--name tmc-backend \
|
||||||
--network traefik \
|
--network traefik \
|
||||||
|
-e PATH_PREFIX=/test-1 \
|
||||||
--label "traefik.enable=true" \
|
--label "traefik.enable=true" \
|
||||||
--label "traefik.http.routers.tmc-backend.rule=Host(\`api.koptilnya.xyz\`) && PathPrefix(\`/test-1\`)" \
|
--label "traefik.http.routers.tmc-backend.rule=Host(\`api.koptilnya.xyz\`) && PathPrefix(\`/test-1\`)" \
|
||||||
--label "traefik.http.routers.tmc-backend.entrypoints=websecure" \
|
--label "traefik.http.routers.tmc-backend.entrypoints=websecure" \
|
||||||
|
|||||||
@@ -4,17 +4,18 @@ import { itemsRouter } from './routes/items.js'
|
|||||||
import { setupSwagger } from './swagger.js'
|
import { setupSwagger } from './swagger.js'
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
|
const prefix = process.env.PATH_PREFIX ?? ''
|
||||||
|
|
||||||
app.use(cors({ origin: 'http://localhost:3000' }))
|
app.use(cors({ origin: 'http://localhost:3000' }))
|
||||||
app.use(express.json())
|
app.use(express.json())
|
||||||
|
|
||||||
setupSwagger(app)
|
setupSwagger(app, prefix)
|
||||||
app.use('/api/items', itemsRouter)
|
app.use(`${prefix}/api/items`, itemsRouter)
|
||||||
|
|
||||||
const PORT = 1337
|
const PORT = 1337
|
||||||
app.listen(PORT, () => {
|
app.listen(PORT, () => {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log(`Server running on http://localhost:${PORT}`)
|
console.log(`Server running on http://localhost:${PORT}`)
|
||||||
// eslint-disable-next-line no-console
|
// 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)
|
const spec = swaggerJsdoc(options)
|
||||||
|
|
||||||
export function setupSwagger(app: Express): void {
|
export function setupSwagger(app: Express, prefix = ''): void {
|
||||||
app.get('/docs/json', (_req, res) => res.json(spec))
|
app.get(`${prefix}/docs/json`, (_req, res) => res.json(spec))
|
||||||
app.use('/docs', swaggerUi.serve, swaggerUi.setup(spec))
|
app.use(`${prefix}/docs`, swaggerUi.serve, swaggerUi.setup(spec))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user