-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from SciPhi-AI/Nolan/EnvVars
Allow runtime env vars
- Loading branch information
Showing
13 changed files
with
134 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
window.__RUNTIME_CONFIG__ = { | ||
NEXT_PUBLIC_R2R_DEPLOYMENT_URL: '__NEXT_PUBLIC_R2R_DEPLOYMENT_URL__', | ||
R2R_DASHBOARD_DISABLE_TELEMETRY: '__R2R_DASHBOARD_DISABLE_TELEMETRY__', | ||
SUPABASE_URL: '__SUPABASE_URL__', | ||
SUPABASE_ANON_KEY: '__SUPABASE_ANON_KEY__', | ||
NEXT_PUBLIC_HATCHET_DASHBOARD_URL: '__NEXT_PUBLIC_HATCHET_DASHBOARD_URL__', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,23 @@ | ||
import { createClient } from '@supabase/supabase-js'; | ||
// lib/supabase.ts | ||
|
||
let supabase: ReturnType<typeof createClient> | null = null; | ||
import { createClient, SupabaseClient } from '@supabase/supabase-js'; | ||
|
||
if (process.env.SUPABASE_URL && process.env.SUPABASE_ANON_KEY) { | ||
supabase = createClient( | ||
process.env.SUPABASE_URL, | ||
process.env.SUPABASE_ANON_KEY | ||
); | ||
} | ||
let supabase: SupabaseClient | null = null; | ||
|
||
export const getSupabase = (): SupabaseClient | null => { | ||
if (typeof window !== 'undefined' && window.__RUNTIME_CONFIG__) { | ||
if (!supabase) { | ||
const supabaseUrl = window.__RUNTIME_CONFIG__.SUPABASE_URL; | ||
const supabaseAnonKey = window.__RUNTIME_CONFIG__.SUPABASE_ANON_KEY; | ||
if (supabaseUrl && supabaseAnonKey) { | ||
supabase = createClient(supabaseUrl, supabaseAnonKey); | ||
} else { | ||
console.warn('Supabase URL or Anon Key is missing in runtime config.'); | ||
} | ||
} | ||
return supabase; | ||
} | ||
return null; | ||
}; | ||
|
||
export { supabase }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ import { useUserContext } from '@/context/UserContext'; | |
import debounce from '@/lib/debounce'; | ||
import { supabase } from '@/lib/supabase'; | ||
|
||
const DEFAULT_DEPLOYMENT_URL = 'http://localhost:7272'; | ||
|
||
const LoginPage: React.FC = () => { | ||
const [email, setEmail] = useState('[email protected]'); | ||
const [password, setPassword] = useState('change_me_immediately'); | ||
|
@@ -26,10 +28,14 @@ const LoginPage: React.FC = () => { | |
const [sanitizedDeploymentUrl, setSanitizedDeploymentUrl] = useState(''); | ||
|
||
useEffect(() => { | ||
const deploymentUrl = | ||
process.env.NEXT_PUBLIC_R2R_DEPLOYMENT_URL || 'http://localhost:7272'; | ||
setRawDeploymentUrl(deploymentUrl); | ||
setSanitizedDeploymentUrl(deploymentUrl); | ||
if (typeof window !== 'undefined') { | ||
const deploymentUrl = | ||
window.__RUNTIME_CONFIG__?.NEXT_PUBLIC_R2R_DEPLOYMENT_URL; | ||
if (deploymentUrl) { | ||
setRawDeploymentUrl(deploymentUrl); | ||
setSanitizedDeploymentUrl(deploymentUrl); | ||
} | ||
} | ||
}, []); | ||
|
||
const handleSubmit = async (e: React.FormEvent) => { | ||
|
@@ -125,14 +131,25 @@ const LoginPage: React.FC = () => { | |
}; | ||
|
||
const sanitizeUrl = (url: string): string => { | ||
const defaultUrl = | ||
process.env.NEXT_PUBLIC_R2R_DEPLOYMENT_URL || 'http://localhost:7272'; | ||
let sanitized = url.trim(); | ||
if ( | ||
typeof window !== 'undefined' && | ||
window.__RUNTIME_CONFIG__?.NEXT_PUBLIC_R2R_DEPLOYMENT_URL | ||
) { | ||
const configUrl = | ||
window.__RUNTIME_CONFIG__.NEXT_PUBLIC_R2R_DEPLOYMENT_URL; | ||
|
||
// If the URL is empty or just a protocol, return the config URL | ||
if (!url || url === 'http://' || url === 'https://') { | ||
return configUrl; | ||
} | ||
} | ||
|
||
if (!sanitized || sanitized === 'http://' || sanitized === 'https://') { | ||
return defaultUrl; | ||
// If no config URL is available, use the default | ||
if (!url || url === 'http://' || url === 'https://') { | ||
return DEFAULT_DEPLOYMENT_URL; | ||
} | ||
|
||
let sanitized = url.trim(); | ||
sanitized = sanitized.replace(/\/+$/, ''); | ||
|
||
if (!/^https?:\/\//i.test(sanitized)) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/sh | ||
|
||
# Function to replace placeholders with environment variables | ||
replace_env_vars() { | ||
echo "Replacing environment variables in env-config.js..." | ||
sed -i "s|__NEXT_PUBLIC_R2R_DEPLOYMENT_URL__|${NEXT_PUBLIC_R2R_DEPLOYMENT_URL}|g" /app/public/env-config.js | ||
sed -i "s|__R2R_DASHBOARD_DISABLE_TELEMETRY__|${R2R_DASHBOARD_DISABLE_TELEMETRY}|g" /app/public/env-config.js | ||
sed -i "s|__SUPABASE_URL__|${SUPABASE_URL}|g" /app/public/env-config.js | ||
sed -i "s|__SUPABASE_ANON_KEY__|${SUPABASE_ANON_KEY}|g" /app/public/env-config.js | ||
sed -i "s|__NEXT_PUBLIC_HATCHET_DASHBOARD_URL__|${NEXT_PUBLIC_HATCHET_DASHBOARD_URL}|g" /app/public/env-config.js | ||
} | ||
|
||
# Replace environment variables | ||
replace_env_vars | ||
|
||
# Start the Next.js server | ||
exec node server.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// types/globals.d.ts | ||
declare global { | ||
interface Window { | ||
__RUNTIME_CONFIG__: { | ||
NEXT_PUBLIC_R2R_DEPLOYMENT_URL: string; | ||
R2R_DASHBOARD_DISABLE_TELEMETRY: string; | ||
SUPABASE_URL: string; | ||
SUPABASE_ANON_KEY: string; | ||
NEXT_PUBLIC_HATCHET_DASHBOARD_URL: string; | ||
}; | ||
} | ||
} | ||
|
||
export {}; |