Skip to content

Commit

Permalink
fix: switch to dynamic private env (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
AyushSehrawat authored Jul 14, 2024
1 parent a02ab94 commit eb8d3d0
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 17 deletions.
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/hooks.server.ts
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/lib/forms/helpers.server.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/routes/+page.server.ts
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/routes/library/+page.server.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/routes/onboarding/1/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/routes/onboarding/2/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/routes/onboarding/3/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/routes/onboarding/4/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/routes/settings/about/+page.server.ts
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/routes/settings/content/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/routes/settings/mediaserver/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/routes/settings/scrapers/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/routes/summary/+page.server.ts
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down

0 comments on commit eb8d3d0

Please sign in to comment.