Skip to content

Commit 4b4951a

Browse files
authored
Merge pull request #1425 from SciCatProject/SWAP-4199-scicat-be-make-swagger-url-configurable-
feat: allow the swagger path to be configurable
2 parents 2a450ad + 55329e7 commit 4b4951a

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ Valid environment variables for the .env file. See [.env.example](/.env.example)
175175
| `ES_FIELDS_LIMIT` | number | | The total number of fields in an index. | 1000 |
176176
| `ES_REFRESH` | string | | If set to `wait_for`, Elasticsearch will wait till data is inserted into the specified index before returning a response. | false |
177177
| `LOGGERS_CONFIG_FILE` | string | | The file name for loggers configuration, located in the project root directory. | "loggers.json" |
178+
| `SWAGGER_PATH` | string | Yes | swaggerPath is the path where the swagger UI will be available| "explorer"|
178179

179180
## Migrating from the old SciCat Backend
180181

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "scicat-backend-next",
3-
"version": "4.0.0",
3+
"version": "4.5.0",
44
"description": "scicat-backend-next",
55
"author": "",
66
"private": true,

src/config/configuration.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ const configuration = () => {
5858
});
5959

6060
const config = {
61+
versions: {
62+
api: "v3",
63+
},
64+
swaggerPath: process.env.SWAGGER_PATH || "explorer",
6165
loggerConfigs: jsonConfigMap.loggers || [defaultLogger],
6266
adminGroups: adminGroups.split(",").map((v) => v.trim()) ?? [],
6367
deleteGroups: deleteGroups.split(",").map((v) => v.trim()) ?? [],

src/main.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ async function bootstrap() {
1515
const app = await NestFactory.create(AppModule, {
1616
bufferLogs: true,
1717
});
18+
const configService: ConfigService<Record<string, unknown>, false> = app.get(
19+
ConfigService,
20+
);
21+
const apiVersion = configService.get<string>("versions.api");
22+
const swaggerPath = `${configService.get<string>("swaggerPath")}`;
1823

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

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

2530
app.enableCors();
26-
app.setGlobalPrefix("api/v3");
31+
32+
app.setGlobalPrefix(`api/${apiVersion}`);
2733
const config = new DocumentBuilder()
2834
.setTitle("SciCat backend API")
2935
.setDescription("This is the API for the SciCat Backend")
30-
.setVersion("" + process.env.npm_package_version)
36+
.setVersion(`api/${apiVersion}`)
3137
.addBearerAuth()
3238
.build();
39+
3340
const document = SwaggerModule.createDocument(app, config);
3441
const swaggerOptions: SwaggerCustomOptions = {
3542
swaggerOptions: {
3643
docExpansion: "none",
3744
},
3845
};
3946

40-
SwaggerModule.setup("explorer", app, document, swaggerOptions);
47+
SwaggerModule.setup(swaggerPath, app, document, swaggerOptions);
4148

4249
app.useGlobalPipes(
4350
/**
@@ -70,10 +77,6 @@ async function bootstrap() {
7077

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

73-
const configService: ConfigService<Record<string, unknown>, false> = app.get(
74-
ConfigService,
75-
);
76-
7780
const expressSessionSecret = configService.get<string>(
7881
"expressSessionSecret",
7982
);

0 commit comments

Comments
 (0)