From eb8d3d0a9010a9389d68dff8c4dd9cbdd6b71944 Mon Sep 17 00:00:00 2001 From: Ayush Sehrawat <69469790+AyushSehrawat@users.noreply.github.com> Date: Sun, 14 Jul 2024 15:54:37 +0530 Subject: [PATCH] fix: switch to dynamic private env (#522) --- Dockerfile | 4 +--- frontend/src/hooks.server.ts | 5 +++-- frontend/src/lib/forms/helpers.server.ts | 3 ++- frontend/src/routes/+page.server.ts | 3 ++- frontend/src/routes/library/+page.server.ts | 3 ++- frontend/src/routes/onboarding/1/+page.server.ts | 3 ++- frontend/src/routes/onboarding/2/+page.server.ts | 3 ++- frontend/src/routes/onboarding/3/+page.server.ts | 3 ++- frontend/src/routes/onboarding/4/+page.server.ts | 3 ++- frontend/src/routes/settings/about/+page.server.ts | 3 ++- frontend/src/routes/settings/content/+page.server.ts | 3 ++- frontend/src/routes/settings/mediaserver/+page.server.ts | 4 +++- frontend/src/routes/settings/scrapers/+page.server.ts | 4 +++- frontend/src/routes/summary/+page.server.ts | 3 ++- 14 files changed, 30 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7bccef22..4fb888b9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,11 +28,9 @@ RUN poetry install --without dev --no-root && rm -rf $POETRY_CACHE_DIR FROM node:20-alpine AS frontend WORKDIR /app COPY frontend/package*.json ./ -ARG BACKEND_URL="" RUN npm install -g pnpm && pnpm install COPY frontend/ . -# RUN pnpm run build && pnpm prune --prod -RUN BACKEND_URL=$BACKEND_URL pnpm run build && pnpm prune --prod +RUN pnpm run build && pnpm prune --prod # Final Image FROM python:3.11-alpine diff --git a/frontend/src/hooks.server.ts b/frontend/src/hooks.server.ts index d86b93c2..78e9438c 100644 --- a/frontend/src/hooks.server.ts +++ b/frontend/src/hooks.server.ts @@ -1,11 +1,12 @@ import type { Handle } from '@sveltejs/kit'; import { redirect, error } from '@sveltejs/kit'; import { sequence } from '@sveltejs/kit/hooks'; -import { BACKEND_URL } from '$env/static/private'; +import { env } from '$env/dynamic/private'; const onboarding: Handle = async ({ event, resolve }) => { if (!event.url.pathname.startsWith('/onboarding') && event.request.method === 'GET') { - const res = await event.fetch(`${BACKEND_URL}/services`); + const BACKEND_URL = env.BACKEND_URL || 'http://127.0.0.1:8080'; + const res = await event.fetch(`${env.BACKEND_URL}/services`); const data = await res.json(); if (!data.success || !data.data) { error(500, 'API Error'); diff --git a/frontend/src/lib/forms/helpers.server.ts b/frontend/src/lib/forms/helpers.server.ts index 6993daf2..fe6b04d1 100644 --- a/frontend/src/lib/forms/helpers.server.ts +++ b/frontend/src/lib/forms/helpers.server.ts @@ -1,4 +1,5 @@ -import { BACKEND_URL } from '$env/static/private'; +import { env } from '$env/dynamic/private'; +const BACKEND_URL = env.BACKEND_URL || 'http://127.0.0.1:8080'; // TODO: Add toCheck export async function setSettings(fetch: any, toSet: any) { diff --git a/frontend/src/routes/+page.server.ts b/frontend/src/routes/+page.server.ts index 17865206..70ccc675 100644 --- a/frontend/src/routes/+page.server.ts +++ b/frontend/src/routes/+page.server.ts @@ -1,6 +1,7 @@ import type { PageServerLoad } from './$types'; import { error } from '@sveltejs/kit'; -import { BACKEND_URL } from '$env/static/private'; +import { env } from '$env/dynamic/private'; +const BACKEND_URL = env.BACKEND_URL || 'http://127.0.0.1:8080'; export const load: PageServerLoad = async ({ fetch }) => { async function getNowPlaying() { diff --git a/frontend/src/routes/library/+page.server.ts b/frontend/src/routes/library/+page.server.ts index c7e9026d..69c85e96 100644 --- a/frontend/src/routes/library/+page.server.ts +++ b/frontend/src/routes/library/+page.server.ts @@ -1,7 +1,8 @@ import type { PageServerLoad } from './$types'; import { error } from '@sveltejs/kit'; import { createQueryString } from '$lib/helpers'; -import { BACKEND_URL } from '$env/static/private'; +import { env } from '$env/dynamic/private'; +const BACKEND_URL = env.BACKEND_URL || 'http://127.0.0.1:8080'; export const load = (async ({ fetch, url }) => { const params = { diff --git a/frontend/src/routes/onboarding/1/+page.server.ts b/frontend/src/routes/onboarding/1/+page.server.ts index bf743e58..a15d4d98 100644 --- a/frontend/src/routes/onboarding/1/+page.server.ts +++ b/frontend/src/routes/onboarding/1/+page.server.ts @@ -7,7 +7,8 @@ import { generalSettingsToGet, generalSettingsToPass } from '$lib/forms/helpers'; -import { BACKEND_URL } from '$env/static/private'; +import { env } from '$env/dynamic/private'; +const BACKEND_URL = env.BACKEND_URL || 'http://127.0.0.1:8080'; export const load: PageServerLoad = async ({ fetch }) => { async function getPartialSettings() { diff --git a/frontend/src/routes/onboarding/2/+page.server.ts b/frontend/src/routes/onboarding/2/+page.server.ts index b5c03466..1bab133a 100644 --- a/frontend/src/routes/onboarding/2/+page.server.ts +++ b/frontend/src/routes/onboarding/2/+page.server.ts @@ -7,7 +7,8 @@ import { mediaServerSettingsToGet, mediaServerSettingsToPass } from '$lib/forms/helpers'; -import { BACKEND_URL } from '$env/static/private'; +import { env } from '$env/dynamic/private'; +const BACKEND_URL = env.BACKEND_URL || 'http://127.0.0.1:8080'; export const load: PageServerLoad = async ({ fetch }) => { async function getPartialSettings() { diff --git a/frontend/src/routes/onboarding/3/+page.server.ts b/frontend/src/routes/onboarding/3/+page.server.ts index 66038c40..f0936e53 100644 --- a/frontend/src/routes/onboarding/3/+page.server.ts +++ b/frontend/src/routes/onboarding/3/+page.server.ts @@ -7,7 +7,8 @@ import { contentSettingsToGet, contentSettingsToPass } from '$lib/forms/helpers'; -import { BACKEND_URL } from '$env/static/private'; +import { env } from '$env/dynamic/private'; +const BACKEND_URL = env.BACKEND_URL || 'http://127.0.0.1:8080'; export const load: PageServerLoad = async ({ fetch }) => { async function getPartialSettings() { diff --git a/frontend/src/routes/onboarding/4/+page.server.ts b/frontend/src/routes/onboarding/4/+page.server.ts index ef32d9a7..a27668e4 100644 --- a/frontend/src/routes/onboarding/4/+page.server.ts +++ b/frontend/src/routes/onboarding/4/+page.server.ts @@ -7,7 +7,8 @@ import { scrapersSettingsToGet, scrapersSettingsToPass } from '$lib/forms/helpers'; -import { BACKEND_URL } from '$env/static/private'; +import { env } from '$env/dynamic/private'; +const BACKEND_URL = env.BACKEND_URL || 'http://127.0.0.1:8080'; export const load: PageServerLoad = async ({ fetch }) => { async function getPartialSettings() { diff --git a/frontend/src/routes/settings/about/+page.server.ts b/frontend/src/routes/settings/about/+page.server.ts index 82aa61c2..ef2ec792 100644 --- a/frontend/src/routes/settings/about/+page.server.ts +++ b/frontend/src/routes/settings/about/+page.server.ts @@ -1,6 +1,7 @@ import type { PageServerLoad } from './$types'; import { error } from '@sveltejs/kit'; -import { BACKEND_URL } from '$env/static/private'; +import { env } from '$env/dynamic/private'; +const BACKEND_URL = env.BACKEND_URL || 'http://127.0.0.1:8080'; export const load: PageServerLoad = async ({ fetch }) => { async function getAboutInfo() { diff --git a/frontend/src/routes/settings/content/+page.server.ts b/frontend/src/routes/settings/content/+page.server.ts index 417c20ab..509c93cf 100644 --- a/frontend/src/routes/settings/content/+page.server.ts +++ b/frontend/src/routes/settings/content/+page.server.ts @@ -9,7 +9,8 @@ import { contentSettingsToSet } from '$lib/forms/helpers'; import { setSettings, saveSettings, loadSettings } from '$lib/forms/helpers.server'; -import { BACKEND_URL } from '$env/static/private'; +import { env } from '$env/dynamic/private'; +const BACKEND_URL = env.BACKEND_URL || 'http://127.0.0.1:8080'; export const load: PageServerLoad = async ({ fetch }) => { async function getPartialSettings() { diff --git a/frontend/src/routes/settings/mediaserver/+page.server.ts b/frontend/src/routes/settings/mediaserver/+page.server.ts index d66fed9a..73a012e4 100644 --- a/frontend/src/routes/settings/mediaserver/+page.server.ts +++ b/frontend/src/routes/settings/mediaserver/+page.server.ts @@ -9,7 +9,9 @@ import { mediaServerSettingsToSet } from '$lib/forms/helpers'; import { setSettings, saveSettings, loadSettings } from '$lib/forms/helpers.server'; -import { BACKEND_URL } from '$env/static/private'; +import { env } from '$env/dynamic/private'; +const BACKEND_URL = env.BACKEND_URL || 'http://127.0.0.1:8080'; + export const load: PageServerLoad = async ({ fetch }) => { async function getPartialSettings() { diff --git a/frontend/src/routes/settings/scrapers/+page.server.ts b/frontend/src/routes/settings/scrapers/+page.server.ts index 68b873ed..c9b7f6d3 100644 --- a/frontend/src/routes/settings/scrapers/+page.server.ts +++ b/frontend/src/routes/settings/scrapers/+page.server.ts @@ -9,7 +9,9 @@ import { scrapersSettingsToSet } from '$lib/forms/helpers'; import { setSettings, saveSettings, loadSettings } from '$lib/forms/helpers.server'; -import { BACKEND_URL } from '$env/static/private'; +import { env } from '$env/dynamic/private'; +const BACKEND_URL = env.BACKEND_URL || 'http://127.0.0.1:8080'; + export const load: PageServerLoad = async ({ fetch }) => { async function getPartialSettings() { diff --git a/frontend/src/routes/summary/+page.server.ts b/frontend/src/routes/summary/+page.server.ts index 8b83f0f4..202bc491 100644 --- a/frontend/src/routes/summary/+page.server.ts +++ b/frontend/src/routes/summary/+page.server.ts @@ -1,6 +1,7 @@ import type { PageServerLoad } from './$types'; import { error } from '@sveltejs/kit'; -import { BACKEND_URL } from '$env/static/private'; +import { env } from '$env/dynamic/private'; +const BACKEND_URL = env.BACKEND_URL || 'http://127.0.0.1:8080'; export const load = (async () => { async function getStats() {