Moved ES variables to .env file

This commit is contained in:
2023-05-30 18:04:00 +02:00
parent 004f266c6b
commit edb3e74c6d
2 changed files with 11 additions and 9 deletions

3
.env.example Normal file
View File

@@ -0,0 +1,3 @@
ES_CLIENT=http://localhost:3200
ES_INDEX=brewlogger-*
ES_APIKEY=

View File

@@ -1,8 +1,9 @@
import { env } from '$env/dynamic/private';
import type IESTelemetry from './interfaces/IESTelemetry';
import type IChartFrame from './interfaces/IChartFrame';
const TELEMETRY_ENDPOINT = 'REPLACE_WITH_ES_HOST/brewlogger-*/_search';
const ES_APIKEY = '***REMOVED***';
const ES_ENDPOINT = `${env.ES_HOST}/${env.ES_INDEX}/_search`;
const ES_APIKEY = env.ES_APIKEY;
function dateToESString(date: Date) {
return date.toISOString();
@@ -148,7 +149,6 @@ function calculateInterval(from, to, interval, size) {
}
function parseTempResponse(data: IESTelemetry): IChartFrame[] {
console.log('got temp response:', data);
return data?.aggregations?.data?.buckets.map((bucket) => {
return {
value: bucket?.maxValue?.value,
@@ -177,9 +177,8 @@ export function fetchTemperature(from: Date, to: Date, size: number = 50): Promi
},
body: JSON.stringify(esSearchQuery)
};
console.log('temp options:', options);
return fetch(TELEMETRY_ENDPOINT, options)
return fetch(ES_ENDPOINT, options)
.then((resp) => resp.json())
.then(parseTempResponse);
}
@@ -200,7 +199,7 @@ export function fetchHumidity(from: Date, to: Date, size: number = 50): Promise<
body: JSON.stringify(esSearchQuery)
};
return fetch(TELEMETRY_ENDPOINT, options)
return fetch(ES_ENDPOINT, options)
.then((resp) => resp.json())
.then(parseTempResponse);
}
@@ -221,7 +220,7 @@ export function fetchPressure(from: Date, to: Date, size: number = 50): Promise<
body: JSON.stringify(esSearchQuery)
};
return fetch(TELEMETRY_ENDPOINT, options)
return fetch(ES_ENDPOINT, options)
.then((resp) => resp.json())
.then(parseTempResponse);
}
@@ -236,7 +235,7 @@ export function getLatestInsideReadings(fetch: Function) {
body: JSON.stringify(buildLatestQuery('inside'))
};
return fetch(TELEMETRY_ENDPOINT, options)
return fetch(ES_ENDPOINT, options)
.then((resp) => resp.json())
.then(parseLatestResponse);
}
@@ -251,7 +250,7 @@ export function getLatestOutsideReadings(fetch: Function) {
body: JSON.stringify(buildLatestQuery('outside'))
};
return fetch(TELEMETRY_ENDPOINT, options)
return fetch(ES_ENDPOINT, options)
.then((resp) => resp.json())
.then(parseLatestResponse);
}