diff --git a/src/config/configuration.ts b/src/config/configuration.ts index 96e9e9bbd..94a190d89 100644 --- a/src/config/configuration.ts +++ b/src/config/configuration.ts @@ -59,7 +59,7 @@ const configuration = () => { const config = { versions: { - api: "v3", + api: "3", }, swaggerPath: process.env.SWAGGER_PATH || "explorer", loggerConfigs: jsonConfigMap.loggers || [defaultLogger], diff --git a/src/main.ts b/src/main.ts index 980dc66a8..3af41b802 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,7 +7,7 @@ import { SwaggerModule, } from "@nestjs/swagger"; import { AppModule } from "./app.module"; -import { Logger, ValidationPipe } from "@nestjs/common"; +import { Logger, ValidationPipe, VersioningType } from "@nestjs/common"; import { ConfigService } from "@nestjs/config"; import { AllExceptionsFilter, ScicatLogger } from "./loggers/logger.service"; @@ -29,11 +29,20 @@ async function bootstrap() { app.enableCors(); - app.setGlobalPrefix(`api/${apiVersion}`); + app.setGlobalPrefix("api"); + + // NOTE: This is a workaround to enable versioning for individual routes + // Version decorator can be used to specify the version for a route + // Read more on https://docs.nestjs.com/techniques/versioning + app.enableVersioning({ + type: VersioningType.URI, + defaultVersion: apiVersion, + }); + const config = new DocumentBuilder() .setTitle("SciCat backend API") .setDescription("This is the API for the SciCat Backend") - .setVersion(`api/${apiVersion}`) + .setVersion(`api/v${apiVersion}`) .addBearerAuth() .build();