Adeen commited on
Commit ·
67bb6b7
1
Parent(s): 03fbbd1
fix: implement runtime environment variable injection for Hugging Face
Browse files- Dockerfile +6 -10
- index.html +1 -0
- src/integrations/supabase/client.ts +6 -2
Dockerfile
CHANGED
|
@@ -9,15 +9,8 @@ RUN npm install
|
|
| 9 |
# Copy source and build
|
| 10 |
COPY . .
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
ARG VITE_SUPABASE_PUBLISHABLE_KEY
|
| 15 |
-
|
| 16 |
-
# Set them as environment variables so Vite picks them up during 'npm run build'
|
| 17 |
-
# if they are not already in a .env file copied in the step above
|
| 18 |
-
ENV VITE_SUPABASE_URL=$VITE_SUPABASE_URL
|
| 19 |
-
ENV VITE_SUPABASE_PUBLISHABLE_KEY=$VITE_SUPABASE_PUBLISHABLE_KEY
|
| 20 |
-
|
| 21 |
RUN npm run build
|
| 22 |
|
| 23 |
# Production stage
|
|
@@ -41,4 +34,7 @@ RUN rm /etc/nginx/conf.d/default.conf && \
|
|
| 41 |
}\n' > /etc/nginx/conf.d/default.conf
|
| 42 |
|
| 43 |
EXPOSE 7860
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
# Copy source and build
|
| 10 |
COPY . .
|
| 11 |
|
| 12 |
+
# Note: We build with placeholders or local .env if present.
|
| 13 |
+
# Secrets will be injected at runtime via env.js
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
RUN npm run build
|
| 15 |
|
| 16 |
# Production stage
|
|
|
|
| 34 |
}\n' > /etc/nginx/conf.d/default.conf
|
| 35 |
|
| 36 |
EXPOSE 7860
|
| 37 |
+
|
| 38 |
+
# At runtime, generate an env.js file that contains the environment variables
|
| 39 |
+
# from Hugging Face Secrets, then start Nginx.
|
| 40 |
+
CMD ["/bin/sh", "-c", "echo \"window.ENV = { VITE_SUPABASE_URL: '$VITE_SUPABASE_URL', VITE_SUPABASE_PUBLISHABLE_KEY: '$VITE_SUPABASE_PUBLISHABLE_KEY' };\" > /usr/share/nginx/html/env.js && exec nginx -g 'daemon off;'"]
|
index.html
CHANGED
|
@@ -4,6 +4,7 @@
|
|
| 4 |
<meta charset="UTF-8" />
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
<title>Source.AI — SOURCE TO YOUR STUDIES</title>
|
|
|
|
| 7 |
<meta name="description" content="Turn PDFs, videos, audio, YouTube and notes into AI-generated study notes, flashcards, quizzes, podcasts and chat.">
|
| 8 |
|
| 9 |
|
|
|
|
| 4 |
<meta charset="UTF-8" />
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
<title>Source.AI — SOURCE TO YOUR STUDIES</title>
|
| 7 |
+
<script src="/env.js"></script>
|
| 8 |
<meta name="description" content="Turn PDFs, videos, audio, YouTube and notes into AI-generated study notes, flashcards, quizzes, podcasts and chat.">
|
| 9 |
|
| 10 |
|
src/integrations/supabase/client.ts
CHANGED
|
@@ -2,8 +2,12 @@
|
|
| 2 |
import { createClient } from '@supabase/supabase-js';
|
| 3 |
import type { Database } from './types';
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
if (!SUPABASE_URL || !SUPABASE_PUBLISHABLE_KEY) {
|
| 9 |
console.error(
|
|
|
|
| 2 |
import { createClient } from '@supabase/supabase-js';
|
| 3 |
import type { Database } from './types';
|
| 4 |
|
| 5 |
+
// Support for runtime environment variable injection on Hugging Face Spaces
|
| 6 |
+
// @ts-ignore
|
| 7 |
+
const runtimeConfig = window.ENV || {};
|
| 8 |
+
|
| 9 |
+
const SUPABASE_URL = runtimeConfig.VITE_SUPABASE_URL || import.meta.env.VITE_SUPABASE_URL;
|
| 10 |
+
const SUPABASE_PUBLISHABLE_KEY = runtimeConfig.VITE_SUPABASE_PUBLISHABLE_KEY || import.meta.env.VITE_SUPABASE_PUBLISHABLE_KEY;
|
| 11 |
|
| 12 |
if (!SUPABASE_URL || !SUPABASE_PUBLISHABLE_KEY) {
|
| 13 |
console.error(
|