diff --git a/.env b/.env index 0322715..d94718a 100644 --- a/.env +++ b/.env @@ -24,3 +24,6 @@ # COOKIE_SECURE=false # COOKIE_SAME_SITE=lax +# Для меню +#RANGES_API_URL=http://192.168.2.39:9999 +#RANGES_API_ENDPOINT=/api/ranges/9999 diff --git a/src/menu/range.service.ts b/src/menu/range.service.ts index 166c123..73dd0d4 100644 --- a/src/menu/range.service.ts +++ b/src/menu/range.service.ts @@ -1,17 +1,27 @@ import { Injectable } from '@nestjs/common'; import { HttpService } from '@nestjs/axios'; import { firstValueFrom } from 'rxjs'; +import { ConfigService } from '@nestjs/config'; @Injectable() export class RangeService { - constructor(private readonly httpService: HttpService) { } + private readonly rangesApiUrl: string; + private readonly rangesApiEndpoint: string; + + constructor( + private readonly httpService: HttpService, + private readonly configService: ConfigService + ) { + this.rangesApiUrl = this.configService.get('RANGES_API_URL', 'localhost:3000'); + this.rangesApiEndpoint = this.configService.get('RANGES_API_ENDPOINT', 'localhost:3000'); + } async getRanges(): Promise>> { try { const response = await firstValueFrom( this.httpService.request({ method: 'OPTIONS', - url: 'http://192.168.2.39:9999/api/ranges/9999', + url: `${this.rangesApiUrl}${this.rangesApiEndpoint}`, headers: { 'Accept': 'application/json' } @@ -55,7 +65,7 @@ export class RangeService { async updateRanges(data: Array<{ name: string; ranges: { min: number; max: number; status: number }[] }>) { try { const response = await firstValueFrom( - this.httpService.post('http://192.168.2.39:9999/api/ranges/9999', data, { + this.httpService.post(`${this.rangesApiUrl}${this.rangesApiEndpoint}`, data, { headers: { 'Content-Type': 'application/json' }, }) ); @@ -65,6 +75,4 @@ export class RangeService { throw new Error('Failed to update ranges'); } } - - } \ No newline at end of file diff --git a/src/prometheus.service.ts b/src/prometheus.service.ts index ac76079..eb685a1 100644 --- a/src/prometheus.service.ts +++ b/src/prometheus.service.ts @@ -124,7 +124,7 @@ export class PrometheusService { async fetchMetricsRange(metric: string, start: number, end: number, step: number, filters: Record = {}): Promise { const query = this.buildFilteredQuery(metric, { ...filters, - instance: '192.168.2.34:9050' // Явно фильтруем по нужному instance + instance: '192.168.2.34:9050' }); try { const response = await lastValueFrom(