Skip to content

Commit

Permalink
Merge pull request #1431 from SciCatProject/SWAP-4214-scicat-be-trans…
Browse files Browse the repository at this point in the history
…fer-api-version-in-url-from-config

refactor: enable versioing for routes
  • Loading branch information
nitrosx authored Sep 27, 2024
2 parents 16aca1b + 4370a8f commit 2c55165
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const configuration = () => {

const config = {
versions: {
api: "v3",
api: "3",
},
swaggerPath: process.env.SWAGGER_PATH || "explorer",
loggerConfigs: jsonConfigMap.loggers || [defaultLogger],
Expand Down
15 changes: 12 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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();

Expand Down

0 comments on commit 2c55165

Please sign in to comment.