From b30c068f9edf80cfa7c117d7f06287c4e6071b43 Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Mon, 23 Feb 2026 20:21:24 +0100 Subject: [PATCH] vite environment variables, also typed --- .env.example | 7 +++---- src/api.ts | 11 +++++++---- src/components/header/SearchInput.vue | 5 +++-- src/vite-env.d.ts | 5 ++--- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.env.example b/.env.example index 78b073f..da0dc81 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,3 @@ -SEASONED_API= -ELASTIC= -ELASTIC_INDEX=shows,movies -SEASONED_DOMAIN= \ No newline at end of file +SEASONED_API=http://localhost:31459 +ELASTIC_URL=http://elastic.local:9200/tmdb-movies-shows +ELASTIC_API_KEY= diff --git a/src/api.ts b/src/api.ts index bbb8c38..d712b1e 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,8 +1,8 @@ import { IList, IMediaCredits, IPersonCredits } from "./interfaces/IList"; -const ELASTIC = import.meta.env.VITE_ELASTIC; -const ELASTIC_INDEX = import.meta.env.VITE_ELASTIC_INDEX; const API_HOSTNAME = import.meta.env.VITE_SEASONED_API; +const ELASTIC_URL = import.meta.env.VITE_ELASTIC_URL; +const ELASTIC_API_KEY = import.meta.env.VITE_ELASTIC_API_KEY; // - - - TMDB - - - @@ -471,7 +471,7 @@ const getEmoji = () => { * @returns {object} List of movies and shows matching query */ const elasticSearchMoviesAndShows = (query, count = 22) => { - const url = new URL(`${ELASTIC_INDEX}/_search`, ELASTIC); + const url = new URL(`${ELASTIC_URL}/_search`); const body = { sort: [{ popularity: { order: "desc" } }, "_score"], @@ -496,7 +496,10 @@ const elasticSearchMoviesAndShows = (query, count = 22) => { const options = { method: "POST", - headers: { "Content-Type": "application/json" }, + headers: { + "Content-Type": "application/json", + Authorization: `ApiKey ${ELASTIC_API_KEY}` + }, body: JSON.stringify(body) }; diff --git a/src/components/header/SearchInput.vue b/src/components/header/SearchInput.vue index 7c0a25e..ef49d74 100644 --- a/src/components/header/SearchInput.vue +++ b/src/components/header/SearchInput.vue @@ -85,8 +85,9 @@ query.value = decodeURIComponent(params.get("query")); } - const { ELASTIC } = process.env; - if (ELASTIC === undefined || ELASTIC === "") { + const ELASTIC_URL = import.meta.env.VITE_ELASTIC_URL; + const ELASTIC_API_KEY = import.meta.env.VITE_ELASTIC_API_KEY; + if (!ELASTIC_URL || !ELASTIC_API_KEY) { disabled.value = true; } diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts index d64601a..17de56c 100644 --- a/src/vite-env.d.ts +++ b/src/vite-env.d.ts @@ -1,8 +1,7 @@ interface ImportMetaEnv { readonly VITE_SEASONED_API: string; - readonly VITE_ELASTIC: string; - readonly VITE_ELASTIC_INDEX: string; - readonly VITE_SEASONED_DOMAIN: string; + readonly VITE_ELASTIC_URL: string; + readonly VITE_ELASTIC_API_KEY: string; } interface ImportMeta {