vite environment variables, also typed

This commit is contained in:
2026-02-23 20:21:24 +01:00
parent 4b68a4ad7c
commit b30c068f9e
4 changed files with 15 additions and 13 deletions

View File

@@ -1,4 +1,3 @@
SEASONED_API=
ELASTIC=
ELASTIC_INDEX=shows,movies
SEASONED_DOMAIN=
SEASONED_API=http://localhost:31459
ELASTIC_URL=http://elastic.local:9200/tmdb-movies-shows
ELASTIC_API_KEY=

View File

@@ -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)
};

View File

@@ -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;
}

5
src/vite-env.d.ts vendored
View File

@@ -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 {