Muhammed Sameer commited on
Commit
d998071
·
1 Parent(s): 6e5bfbf

Safely configure API URLs for production fallback

Browse files
src/components/Admin/TalentClusters.jsx CHANGED
@@ -360,19 +360,20 @@ export default function TalentClusters() {
360
  const runClustering = async () => {
361
  setIsClusteringRunning(true);
362
  try {
363
- const response = await fetch('http://localhost:8000/run-clustering', {
 
364
  method: 'POST',
365
  headers: { 'Content-Type': 'application/json' }
366
  });
367
-
368
  if (!response.ok) {
369
  throw new Error('Failed to start clustering');
370
  }
371
-
372
  const data = await response.json();
373
  console.log('✅ Clustering started:', data);
374
  alert('Clustering pipeline started! This may take a few minutes. You will be notified when complete.');
375
-
376
  // Poll for completion (check every 5 seconds for up to 5 minutes)
377
  const pollInterval = setInterval(async () => {
378
  try {
@@ -384,7 +385,7 @@ export default function TalentClusters() {
384
  .select('cluster_label')
385
  .not('cluster_label', 'is', null)
386
  .limit(1);
387
-
388
  if (profiles && profiles.length > 0) {
389
  clearInterval(pollInterval);
390
  setIsClusteringRunning(false);
@@ -394,10 +395,10 @@ export default function TalentClusters() {
394
  console.log('Still clustering...');
395
  }
396
  }, 5000);
397
-
398
  // Clear interval after 5 minutes
399
  setTimeout(() => clearInterval(pollInterval), 5 * 60 * 1000);
400
-
401
  } catch (err) {
402
  console.error('Error starting clustering:', err);
403
  alert('Failed to start clustering. Check the backend logs.');
 
360
  const runClustering = async () => {
361
  setIsClusteringRunning(true);
362
  try {
363
+ const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:8000';
364
+ const response = await fetch(`${API_URL}/run-clustering`, {
365
  method: 'POST',
366
  headers: { 'Content-Type': 'application/json' }
367
  });
368
+
369
  if (!response.ok) {
370
  throw new Error('Failed to start clustering');
371
  }
372
+
373
  const data = await response.json();
374
  console.log('✅ Clustering started:', data);
375
  alert('Clustering pipeline started! This may take a few minutes. You will be notified when complete.');
376
+
377
  // Poll for completion (check every 5 seconds for up to 5 minutes)
378
  const pollInterval = setInterval(async () => {
379
  try {
 
385
  .select('cluster_label')
386
  .not('cluster_label', 'is', null)
387
  .limit(1);
388
+
389
  if (profiles && profiles.length > 0) {
390
  clearInterval(pollInterval);
391
  setIsClusteringRunning(false);
 
395
  console.log('Still clustering...');
396
  }
397
  }, 5000);
398
+
399
  // Clear interval after 5 minutes
400
  setTimeout(() => clearInterval(pollInterval), 5 * 60 * 1000);
401
+
402
  } catch (err) {
403
  console.error('Error starting clustering:', err);
404
  alert('Failed to start clustering. Check the backend logs.');
src/components/CandidateDrawer.jsx CHANGED
@@ -25,7 +25,8 @@ const CandidateDrawer = ({ isOpen, onClose, candidate }) => {
25
  const fetchAnalysis = async () => {
26
  setLoadingAnalysis(true);
27
  try {
28
- const response = await fetch('http://localhost:8000/analyze-candidate', {
 
29
  method: 'POST',
30
  headers: { 'Content-Type': 'application/json' },
31
  body: JSON.stringify({
 
25
  const fetchAnalysis = async () => {
26
  setLoadingAnalysis(true);
27
  try {
28
+ const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:8000';
29
+ const response = await fetch(`${API_URL}/analyze-candidate`, {
30
  method: 'POST',
31
  headers: { 'Content-Type': 'application/json' },
32
  body: JSON.stringify({
src/pages/ApplicantATS.jsx CHANGED
@@ -58,7 +58,8 @@ export default function ApplicantATS({ onNavigate }) {
58
  formData.append("job_description", jobDescription);
59
 
60
  try {
61
- const response = await fetch("http://localhost:8000/analyze-ats", {
 
62
  method: "POST",
63
  body: formData,
64
  });
@@ -153,8 +154,8 @@ export default function ApplicantATS({ onNavigate }) {
153
  </div>
154
  <p style={{ fontSize: '1.25rem', color: '#d1d5db' }}>ATS Match Score</p>
155
  <p style={{ color: '#d1d5db', marginTop: '0.5rem', marginBottom: '1.5rem' }}>{analysisResult.summary}</p>
156
-
157
- <button
158
  onClick={() => setShowBuilder(true)}
159
  style={{
160
  backgroundColor: '#FBBF24',
 
58
  formData.append("job_description", jobDescription);
59
 
60
  try {
61
+ const API_URL = import.meta.env.VITE_API_URL || "http://localhost:8000";
62
+ const response = await fetch(`${API_URL}/analyze-ats`, {
63
  method: "POST",
64
  body: formData,
65
  });
 
154
  </div>
155
  <p style={{ fontSize: '1.25rem', color: '#d1d5db' }}>ATS Match Score</p>
156
  <p style={{ color: '#d1d5db', marginTop: '0.5rem', marginBottom: '1.5rem' }}>{analysisResult.summary}</p>
157
+
158
+ <button
159
  onClick={() => setShowBuilder(true)}
160
  style={{
161
  backgroundColor: '#FBBF24',