From 2edb253eada5028248420b2f99941c1667962737 Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Tue, 30 May 2023 18:28:22 +0200 Subject: [PATCH] All env variables imported during build time --- src/lib/server/graphQueryGenerator.ts | 5 ++--- src/routes/+page.server.ts | 7 +++---- src/routes/api/relay/[location]/+server.ts | 6 ++---- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/lib/server/graphQueryGenerator.ts b/src/lib/server/graphQueryGenerator.ts index ad1d3b7..b9e1255 100644 --- a/src/lib/server/graphQueryGenerator.ts +++ b/src/lib/server/graphQueryGenerator.ts @@ -1,9 +1,8 @@ -import { env } from '$env/dynamic/private'; +import { ES_HOST, ES_INDEX, ES_APIKEY } from '$env/static/private'; import type IESTelemetry from './interfaces/IESTelemetry'; import type IChartFrame from './interfaces/IChartFrame'; -const ES_ENDPOINT = `${env.ES_HOST}/${env.ES_INDEX}/_search`; -const ES_APIKEY = env.ES_APIKEY; +const ES_ENDPOINT = `${ES_HOST}/${ES_INDEX}/_search`; function dateToESString(date: Date) { return date.toISOString(); diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts index c1d290d..e72ded5 100644 --- a/src/routes/+page.server.ts +++ b/src/routes/+page.server.ts @@ -1,9 +1,8 @@ -import { env } from '$env/dynamic/private'; +import { BREWLOGGER_HOST } from '$env/static/private'; import type { PageServerLoad } from './$types'; -const host = env.BREWLOGGER_HOST; -const sensorsUrl = `${host}/api/sensors`; -const relaysUrl = `${host}/api/relays`; +const sensorsUrl = `${BREWLOGGER_HOST}/api/sensors`; +const relaysUrl = `${BREWLOGGER_HOST}/api/relays`; async function getSensors() { return fetch(sensorsUrl) diff --git a/src/routes/api/relay/[location]/+server.ts b/src/routes/api/relay/[location]/+server.ts index 545e17c..afb4a0d 100644 --- a/src/routes/api/relay/[location]/+server.ts +++ b/src/routes/api/relay/[location]/+server.ts @@ -1,14 +1,12 @@ import { json, RequestEvent } from '@sveltejs/kit'; -import { env } from '$env/dynamic/private'; +import { BREWLOGGER_HOST } from '$env/static/private'; import type { RequestHandler } from './$types'; -const BREWPI_URL = env.BREWLOGGER_HOST; - export const POST = (async (event: RequestEvent) => { const { pathname } = new URL(event.request.url); const options = { method: 'POST' }; - return fetch(BREWPI_URL + pathname, options) + return fetch(BREWLOGGER_HOST + pathname, options) .then((resp) => resp.json()) .then((response) => json(response)); }) satisfies RequestHandler;