Hkoradiya123 commited on
Commit
9a10d7c
·
1 Parent(s): 8d6d081

Load frontend config from runtime env

Browse files
Backend/app.py CHANGED
@@ -1,6 +1,7 @@
1
  import os
 
2
  import logging
3
- from flask import Flask, jsonify, request, send_from_directory
4
  from flask_cors import CORS
5
  from dotenv import load_dotenv
6
 
@@ -60,6 +61,20 @@ def health():
60
  })
61
 
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  @app.route('/', defaults={'path': ''})
64
  @app.route('/<path:path>')
65
  def serve_frontend(path):
 
1
  import os
2
+ import json
3
  import logging
4
+ from flask import Flask, jsonify, request, send_from_directory, Response
5
  from flask_cors import CORS
6
  from dotenv import load_dotenv
7
 
 
61
  })
62
 
63
 
64
+ @app.route('/config.js')
65
+ def config_js():
66
+ supabase_url = os.getenv('VITE_SUPABASE_URL') or os.getenv('SUPABASE_URL') or ''
67
+ supabase_anon = os.getenv('VITE_SUPABASE_ANON_KEY') or os.getenv('SUPABASE_ANON_KEY') or ''
68
+ api_url = os.getenv('VITE_API_URL') or ''
69
+ payload = {
70
+ "VITE_SUPABASE_URL": supabase_url,
71
+ "VITE_SUPABASE_ANON_KEY": supabase_anon,
72
+ "VITE_API_URL": api_url,
73
+ }
74
+ js = f"window.__APP_CONFIG__ = {json.dumps(payload)};"
75
+ return Response(js, mimetype='application/javascript')
76
+
77
+
78
  @app.route('/', defaults={'path': ''})
79
  @app.route('/<path:path>')
80
  def serve_frontend(path):
Frontend/index.html CHANGED
@@ -10,6 +10,7 @@
10
 
11
  <body>
12
  <div id="root"></div>
 
13
  <script type="module" src="/src/main.jsx"></script>
14
  </body>
15
  </html>
 
10
 
11
  <body>
12
  <div id="root"></div>
13
+ <script src="/config.js"></script>
14
  <script type="module" src="/src/main.jsx"></script>
15
  </body>
16
  </html>
Frontend/src/utils/api.js CHANGED
@@ -1 +1,2 @@
1
- export const API_BASE_URL = import.meta.env.VITE_API_URL || window.location.origin;
 
 
1
+ const runtimeConfig = (typeof window !== 'undefined' && window.__APP_CONFIG__) || {};
2
+ export const API_BASE_URL = runtimeConfig.VITE_API_URL || import.meta.env.VITE_API_URL || window.location.origin;
Frontend/src/utils/supabaseClient.js CHANGED
@@ -1,7 +1,8 @@
1
  import { createClient } from '@supabase/supabase-js';
2
 
3
- const supabaseUrl = import.meta.env.VITE_SUPABASE_URL || '';
4
- const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY || '';
 
5
 
6
  if (!supabaseUrl || !supabaseAnonKey) {
7
  console.warn("Supabase URL or Anon Key is missing. Please set VITE_SUPABASE_URL and VITE_SUPABASE_ANON_KEY in your .env");
 
1
  import { createClient } from '@supabase/supabase-js';
2
 
3
+ const runtimeConfig = (typeof window !== 'undefined' && window.__APP_CONFIG__) || {};
4
+ const supabaseUrl = runtimeConfig.VITE_SUPABASE_URL || import.meta.env.VITE_SUPABASE_URL || '';
5
+ const supabaseAnonKey = runtimeConfig.VITE_SUPABASE_ANON_KEY || import.meta.env.VITE_SUPABASE_ANON_KEY || '';
6
 
7
  if (!supabaseUrl || !supabaseAnonKey) {
8
  console.warn("Supabase URL or Anon Key is missing. Please set VITE_SUPABASE_URL and VITE_SUPABASE_ANON_KEY in your .env");