From 9055c453843120f58b833a7d83af988ac53c451a Mon Sep 17 00:00:00 2001 From: Rotimi Best Date: Sun, 7 Sep 2025 10:24:34 +0100 Subject: [PATCH] chore: move IS_SELFHOSTED to public env --- apps/dashboard/.env.example | 2 +- apps/dashboard/Dockerfile | 4 ++-- apps/dashboard/src/lib/utils/store/org.ts | 4 ++-- apps/dashboard/src/routes/+layout.server.ts | 11 ++++++----- apps/dashboard/svelte.config.js | 2 +- docker-compose.yaml | 2 +- package.json | 2 +- turbo.json | 2 +- 8 files changed, 15 insertions(+), 14 deletions(-) diff --git a/apps/dashboard/.env.example b/apps/dashboard/.env.example index 25b65ee5..e7020732 100644 --- a/apps/dashboard/.env.example +++ b/apps/dashboard/.env.example @@ -4,7 +4,7 @@ PUBLIC_SUPABASE_ANON_KEY= PRIVATE_SUPABASE_SERVICE_ROLE= # Selfhosting - should be true if you are selfhosting -IS_SELFHOSTED=false +PUBLIC_IS_SELFHOSTED=false DEPLOYMENT_PROVIDER= # docker or empty. empty will use adapter-auto for sveltekit build # Unsplash setup - Optional if you want to use Unsplash images diff --git a/apps/dashboard/Dockerfile b/apps/dashboard/Dockerfile index b47641cd..ae9df640 100644 --- a/apps/dashboard/Dockerfile +++ b/apps/dashboard/Dockerfile @@ -30,7 +30,7 @@ RUN pnpm install COPY apps/dashboard ./apps/dashboard # Set env vars for SvelteKit to use Node adapter -ENV IS_SELFHOSTED=true \ +ENV PUBLIC_IS_SELFHOSTED=true \ DEPLOYMENT_PROVIDER=docker \ PUBLIC_SUPABASE_URL=$PUBLIC_SUPABASE_URL \ PUBLIC_SUPABASE_ANON_KEY=$PUBLIC_SUPABASE_ANON_KEY \ @@ -67,7 +67,7 @@ EXPOSE 3000 # Set environment variables for production ENV NODE_ENV=production \ - IS_SELFHOSTED=true \ + PUBLIC_IS_SELFHOSTED=true \ DEPLOYMENT_PROVIDER=docker \ PUBLIC_SUPABASE_URL=$PUBLIC_SUPABASE_URL \ PUBLIC_SUPABASE_ANON_KEY=$PUBLIC_SUPABASE_ANON_KEY \ diff --git a/apps/dashboard/src/lib/utils/store/org.ts b/apps/dashboard/src/lib/utils/store/org.ts index 2ff2deb0..35015c6f 100644 --- a/apps/dashboard/src/lib/utils/store/org.ts +++ b/apps/dashboard/src/lib/utils/store/org.ts @@ -7,7 +7,7 @@ import { ROLE } from '$lib/utils/constants/roles'; import { STEPS } from '../constants/quiz'; import type { UserLessonDataType } from '$lib/utils/types'; import type { Writable } from 'svelte/store'; -import { env } from '$env/dynamic/public'; +import { PUBLIC_IS_SELFHOSTED } from '$env/static/public'; // Trigger build export const defaultCurrentOrgState: CurrentOrg = { @@ -70,7 +70,7 @@ export const currentOrgDomain = derived(currentOrg, ($currentOrg) => { }); export const isFreePlan = derived(currentOrg, ($currentOrg) => { - if (!$currentOrg.id || env.IS_SELFHOSTED === 'true') return false; + if (!$currentOrg.id || PUBLIC_IS_SELFHOSTED === 'true') return false; const plan = getActivePlan($currentOrg); diff --git a/apps/dashboard/src/routes/+layout.server.ts b/apps/dashboard/src/routes/+layout.server.ts index f53a9323..0f22797b 100644 --- a/apps/dashboard/src/routes/+layout.server.ts +++ b/apps/dashboard/src/routes/+layout.server.ts @@ -1,7 +1,7 @@ import { getSupabase, supabase } from '$lib/utils/functions/supabase'; import type { CurrentOrg } from '$lib/utils/types/org'; -import { IS_SELFHOSTED } from '$env/static/private'; +import { PUBLIC_IS_SELFHOSTED } from '$env/static/public'; import type { MetaTagsProps } from 'svelte-meta-tags'; import { blockedSubdomain } from '$lib/utils/constants/app'; import { dev } from '$app/environment'; @@ -13,7 +13,7 @@ if (!supabase) { getSupabase(); } -export const ssr = IS_SELFHOSTED === 'true' ? false : true; +export const ssr = PUBLIC_IS_SELFHOSTED === 'true' ? false : true; interface LoadOutput { orgSiteName: string; @@ -36,10 +36,10 @@ export const load = async ({ url, cookies, request }): Promise => { serverLang: request.headers?.get('accept-language') || '' }; - console.log('IS_SELFHOSTED', IS_SELFHOSTED); + console.log('PUBLIC_IS_SELFHOSTED', PUBLIC_IS_SELFHOSTED); // Selfhosted usecase would be here - if (IS_SELFHOSTED === 'true') { + if (PUBLIC_IS_SELFHOSTED === 'true') { const subdomain = getSubdomain(url); console.log('subdomain', subdomain); @@ -87,7 +87,8 @@ export const load = async ({ url, cookies, request }): Promise => { console.log('custom domain response.org', response.org); if (!response.org) { - throw redirect(307, 'https://app.classroomio.com/404?type=org'); + console.error('Custom domain org not found, loading dashboard'); + return response; } response.isOrgSite = true; diff --git a/apps/dashboard/svelte.config.js b/apps/dashboard/svelte.config.js index 571a51b9..17bd517b 100644 --- a/apps/dashboard/svelte.config.js +++ b/apps/dashboard/svelte.config.js @@ -7,7 +7,7 @@ import path from 'path'; import 'dotenv/config'; const useNodeAdapter = - process.env.IS_SELFHOSTED === 'true' && process.env.DEPLOYMENT_PROVIDER === 'docker'; + process.env.PUBLIC_IS_SELFHOSTED === 'true' && process.env.DEPLOYMENT_PROVIDER === 'docker'; /** @type {import('@sveltejs/kit').Config} */ const config = { diff --git a/docker-compose.yaml b/docker-compose.yaml index c6707e05..975cccb1 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -68,7 +68,7 @@ services: - /app/node_modules - /app/apps/dashboard/node_modules environment: - - IS_SELFHOSTED=true + - PUBLIC_IS_SELFHOSTED=true - DEPLOYMENT_PROVIDER=docker # Supabase - Database - PUBLIC_SUPABASE_URL=${PUBLIC_SUPABASE_URL} diff --git a/package.json b/package.json index b96ecf7b..1c04ca1f 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "release": "standard-version", "ci": "cypress run", "supabase": "pnpx supabase", - "dashboard:build": "cd apps/dashboard && pnpm i && IS_SELFHOSTED=true NODE_OPTIONS='--max-old-space-size=20384' DEPLOYMENT_PROVIDER=docker pnpm build", + "dashboard:build": "cd apps/dashboard && pnpm i && PUBLIC_IS_SELFHOSTED=true NODE_OPTIONS='--max-old-space-size=20384' DEPLOYMENT_PROVIDER=docker pnpm build", "dashboard:start": "cd apps/dashboard && node build" }, "license": "MIT", diff --git a/turbo.json b/turbo.json index eb6c7e5d..041f076a 100644 --- a/turbo.json +++ b/turbo.json @@ -1,6 +1,6 @@ { "$schema": "https://turbo.build/schema.json", - "globalEnv": ["IS_SELFHOSTED", "DEPLOYMENT_PROVIDER"], + "globalEnv": ["PUBLIC_IS_SELFHOSTED", "DEPLOYMENT_PROVIDER"], "pipeline": { "build": { "dependsOn": ["^build"],