env prefix
All checks were successful
Deploy Backend / deploy (push) Successful in 34s

This commit is contained in:
Oscar
2026-06-04 15:40:35 +03:00
parent 52540658b4
commit 0a203d971e
3 changed files with 8 additions and 6 deletions

View File

@@ -35,6 +35,7 @@ jobs:
docker run -d \
--name tmc-backend \
--network traefik \
-e PATH_PREFIX=/test-1 \
--label "traefik.enable=true" \
--label "traefik.http.routers.tmc-backend.rule=Host(\`api.koptilnya.xyz\`) && PathPrefix(\`/test-1\`)" \
--label "traefik.http.routers.tmc-backend.entrypoints=websecure" \

View File

@@ -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`)
})

View File

@@ -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))
}