Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow the swagger path to be configurable #1425

Merged
merged 4 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading