-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bdf6f54
commit cf0ebfe
Showing
6 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsString, IsUrl } from 'class-validator'; | ||
|
||
export class GetInfoDto { | ||
@ApiProperty({ | ||
example: '7.17', | ||
description: 'Elasticsearch version', | ||
}) | ||
@IsString() | ||
elasticsearchVersion: string; | ||
|
||
@ApiProperty({ | ||
example: '1.0.4', | ||
description: 'Matching API Version', | ||
}) | ||
@IsString() | ||
APIversion: string; | ||
|
||
@ApiProperty({ | ||
example: '1.0.4', | ||
description: 'Matching API Version', | ||
}) | ||
@IsUrl({ | ||
require_tld: false, | ||
}) | ||
docs: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Get, Req, Controller } from '@nestjs/common'; | ||
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; | ||
import { readFileSync } from 'fs'; | ||
import path from 'path'; | ||
import { ElasticService } from '../shared/elasticsearch/elastic.service'; | ||
import { Public } from '../common/decorators/auth.decorator'; | ||
import { Request } from '../common/helpers/request.interface'; | ||
import { GetInfoDto } from './dto/get-info.dto'; | ||
|
||
@ApiTags('Info') | ||
@Controller() | ||
export class InfoController { | ||
constructor(private readonly elasticService: ElasticService) {} | ||
|
||
@Get() | ||
@ApiOperation({ | ||
description: 'Get API info', | ||
summary: 'Public', | ||
}) | ||
@ApiResponse({ | ||
status: 200, | ||
description: 'Return API Info', | ||
}) | ||
@Public() | ||
async getInfo(@Req() req: Request<unknown>): Promise<GetInfoDto> { | ||
const pathEndpoint = `${req.protocol}://${req.hostname}${req.client.localPort ? `:${req.client.localPort}` : ''}${ | ||
req.url | ||
}`; | ||
const packageJsonPath = path.join(__dirname, '../..', 'package.json'); | ||
const packageJsonString = readFileSync(packageJsonPath, 'utf8'); | ||
const packageJson = JSON.parse(packageJsonString) as { version: string }; | ||
|
||
const elsInfo = await this.elasticService.getInfo(); | ||
|
||
return { | ||
APIversion: packageJson.version, | ||
// prettier-ignore | ||
elasticsearchVersion: (elsInfo.body as { version: { "number": string } }).version.number, | ||
docs: `${pathEndpoint}api/v1/docs`, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { ElasticModule } from '../shared/elasticsearch/elastic.module'; | ||
import { InfoController } from './info.controller'; | ||
|
||
@Module({ | ||
imports: [ElasticModule], | ||
providers: [], | ||
controllers: [InfoController], | ||
exports: [], | ||
}) | ||
export class InfoModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,4 +88,8 @@ export class ElasticService { | |
index, | ||
}); | ||
} | ||
|
||
async getInfo() { | ||
return this.elasticsearchService.info(); | ||
} | ||
} |