Skip to content

Commit

Permalink
Merge pull request #1425 from SciCatProject/SWAP-4199-scicat-be-make-…
Browse files Browse the repository at this point in the history
…swagger-url-configurable-

feat: allow the swagger path to be configurable
  • Loading branch information
nitrosx authored Sep 19, 2024
2 parents 2a450ad + 55329e7 commit 4b4951a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ Valid environment variables for the .env file. See [.env.example](/.env.example)
| `ES_FIELDS_LIMIT` | number | | The total number of fields in an index. | 1000 |
| `ES_REFRESH` | string | | If set to `wait_for`, Elasticsearch will wait till data is inserted into the specified index before returning a response. | false |
| `LOGGERS_CONFIG_FILE` | string | | The file name for loggers configuration, located in the project root directory. | "loggers.json" |
| `SWAGGER_PATH` | string | Yes | swaggerPath is the path where the swagger UI will be available| "explorer"|

## Migrating from the old SciCat Backend

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scicat-backend-next",
"version": "4.0.0",
"version": "4.5.0",
"description": "scicat-backend-next",
"author": "",
"private": true,
Expand Down
4 changes: 4 additions & 0 deletions src/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ const configuration = () => {
});

const config = {
versions: {
api: "v3",
},
swaggerPath: process.env.SWAGGER_PATH || "explorer",
loggerConfigs: jsonConfigMap.loggers || [defaultLogger],
adminGroups: adminGroups.split(",").map((v) => v.trim()) ?? [],
deleteGroups: deleteGroups.split(",").map((v) => v.trim()) ?? [],
Expand Down
17 changes: 10 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ async function bootstrap() {
const app = await NestFactory.create(AppModule, {
bufferLogs: true,
});
const configService: ConfigService<Record<string, unknown>, false> = app.get(
ConfigService,
);
const apiVersion = configService.get<string>("versions.api");
const swaggerPath = `${configService.get<string>("swaggerPath")}`;

const scicatLogger = app.get<ScicatLogger>(ScicatLogger);

Expand All @@ -23,21 +28,23 @@ async function bootstrap() {
app.useGlobalFilters(new AllExceptionsFilter(scicatLogger));

app.enableCors();
app.setGlobalPrefix("api/v3");

app.setGlobalPrefix(`api/${apiVersion}`);
const config = new DocumentBuilder()
.setTitle("SciCat backend API")
.setDescription("This is the API for the SciCat Backend")
.setVersion("" + process.env.npm_package_version)
.setVersion(`api/${apiVersion}`)
.addBearerAuth()
.build();

const document = SwaggerModule.createDocument(app, config);
const swaggerOptions: SwaggerCustomOptions = {
swaggerOptions: {
docExpansion: "none",
},
};

SwaggerModule.setup("explorer", app, document, swaggerOptions);
SwaggerModule.setup(swaggerPath, app, document, swaggerOptions);

app.useGlobalPipes(
/**
Expand Down Expand Up @@ -70,10 +77,6 @@ async function bootstrap() {

app.use(json({ limit: "16mb" }));

const configService: ConfigService<Record<string, unknown>, false> = app.get(
ConfigService,
);

const expressSessionSecret = configService.get<string>(
"expressSessionSecret",
);
Expand Down

0 comments on commit 4b4951a

Please sign in to comment.