diff --git a/.gitea/workflows/deploy-backend.yml b/.gitea/workflows/deploy-backend.yml index 7ba5fef..e1f879f 100644 --- a/.gitea/workflows/deploy-backend.yml +++ b/.gitea/workflows/deploy-backend.yml @@ -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" \ diff --git a/backend/src/index.ts b/backend/src/index.ts index f61c037..7dc7f37 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -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`) }) diff --git a/backend/src/swagger.ts b/backend/src/swagger.ts index 8d1162d..eb0424e 100644 --- a/backend/src/swagger.ts +++ b/backend/src/swagger.ts @@ -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)) }