Spaces:
Sleeping
Sleeping
fix: implement proper Astro environment variables for Hugging Face deployment
Browse files- Replace vite.define with Astro's native env schema system
- Use astro:env/client imports for client-side environment variables
- Update environment variable access to use SUPABASE_URL and SUPABASE_ANON_KEY
- Add Hugging Face deployment instructions to .env.example
- Ensure environment variables are properly exposed to browser
- .env.example +3 -1
- astro.config.mjs +7 -7
- src/pages/index.astro +2 -1
.env.example
CHANGED
|
@@ -14,4 +14,6 @@ SUPABASE_ANON_KEY=your_supabase_anon_key
|
|
| 14 |
# 4. Replace the placeholder values above
|
| 15 |
# 5. Save this file as .env (remove the .example extension)
|
| 16 |
# 6. Run the SQL queries from README.md to set up your database
|
| 17 |
-
#
|
|
|
|
|
|
|
|
|
| 14 |
# 4. Replace the placeholder values above
|
| 15 |
# 5. Save this file as .env (remove the .example extension)
|
| 16 |
# 6. Run the SQL queries from README.md to set up your database
|
| 17 |
+
# 7. For Hugging Face Spaces, add these as regular environment variables
|
| 18 |
+
# (not secrets) with the same names: SUPABASE_URL, SUPABASE_ANON_KEY
|
| 19 |
+
# =================================================================
|
astro.config.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
| 1 |
-
import { defineConfig } from "astro/config";
|
| 2 |
|
| 3 |
export default defineConfig({
|
| 4 |
server: {
|
| 5 |
host: true,
|
| 6 |
port: 4321,
|
| 7 |
},
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
}
|
| 13 |
-
}
|
| 14 |
});
|
|
|
|
| 1 |
+
import { defineConfig, envField } from "astro/config";
|
| 2 |
|
| 3 |
export default defineConfig({
|
| 4 |
server: {
|
| 5 |
host: true,
|
| 6 |
port: 4321,
|
| 7 |
},
|
| 8 |
+
env: {
|
| 9 |
+
schema: {
|
| 10 |
+
SUPABASE_URL: envField.string({ context: "client", access: "public" }),
|
| 11 |
+
SUPABASE_ANON_KEY: envField.string({ context: "client", access: "public" }),
|
| 12 |
+
},
|
| 13 |
+
},
|
| 14 |
});
|
src/pages/index.astro
CHANGED
|
@@ -2,6 +2,7 @@
|
|
| 2 |
import BaseLayout from '../layouts/BaseLayout.astro';
|
| 3 |
import { loadSpeakingData, loadWritingData } from '../utils/loadData';
|
| 4 |
import LoginForm from '../components/LoginForm.astro';
|
|
|
|
| 5 |
|
| 6 |
const ITEMS_PER_PAGE = 5;
|
| 7 |
|
|
@@ -223,7 +224,7 @@ const initialPageInfo = totalItems === 0 ? 'Page 0 of 0' : `Page 1 of ${totalPag
|
|
| 223 |
</main>
|
| 224 |
</div>
|
| 225 |
|
| 226 |
-
<script define:vars={{ supabaseUrl:
|
| 227 |
// Import Supabase
|
| 228 |
import { createClient } from 'https://cdn.jsdelivr.net/npm/@supabase/supabase-js/+esm';
|
| 229 |
|
|
|
|
| 2 |
import BaseLayout from '../layouts/BaseLayout.astro';
|
| 3 |
import { loadSpeakingData, loadWritingData } from '../utils/loadData';
|
| 4 |
import LoginForm from '../components/LoginForm.astro';
|
| 5 |
+
import { SUPABASE_URL, SUPABASE_ANON_KEY } from 'astro:env/client';
|
| 6 |
|
| 7 |
const ITEMS_PER_PAGE = 5;
|
| 8 |
|
|
|
|
| 224 |
</main>
|
| 225 |
</div>
|
| 226 |
|
| 227 |
+
<script define:vars={{ supabaseUrl: SUPABASE_URL, supabaseAnonKey: SUPABASE_ANON_KEY, defaultCategory, speakingRecords, writingRecords }} type="module">
|
| 228 |
// Import Supabase
|
| 229 |
import { createClient } from 'https://cdn.jsdelivr.net/npm/@supabase/supabase-js/+esm';
|
| 230 |
|