You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
HMG_QLine/CONFIGURATION_API_STATUS.md

4.7 KiB

Configuration API - Status Update

Question Asked

"What about the API call to get the configuration? I don't see any API call? API: Common_Config_GetByIP"

Answer

✅ The API Call EXISTS!

Location: /lib/repositories/screen_details_repo.dart
Method: getGlobalScreenConfigurations() (lines 41-70)
Endpoint: ApiConstants.commonConfigGet → https://ms.hmg.com/nscapi/api/PatientCall/Common_Config_GetByIP

Code:

Future<GlobalConfigurationsModel?> getGlobalScreenConfigurations({required String ipAddress}) async {
  try {
    var params = {
      "ipAddress": ipAddress.toString(),
      "apiKey": AppConstants.apiKey.toString(),
    };
    GenericRespModel genericModel = await apiClientInstance.postJsonForObject(
      (json) => GenericRespModel.fromJson(json),
      ApiConstants.commonConfigGet,  // ← Uses Common_Config_GetByIP
      params,
    );
    // ... returns GlobalConfigurationsModel
  } catch (e) {
    // Error handling
  }
}

⚠️ The Problem

The try-catch was commented out in the original code, which meant:

  1. CORS errors wouldn't be caught properly
  2. Errors would bubble up and crash initialization
  3. No clear error messages for debugging

✅ What Was Fixed

  1. Uncommented the try-catch block
  2. Added CORS-specific error detection
  3. Added comprehensive error logging

Now the code:

  • Catches CORS errors gracefully
  • Logs detailed error information
  • Shows user-friendly error messages
  • Detects if the error is CORS-related

🔍 When Is This Called?

Call Chain:

Splash Screen
  └─> waitForIPAndInitializeConfigVM()
      └─> initializeScreenConfigVM()
          └─> getGlobalConfigurationsByIP()
              └─> screenDetailsRepo.getGlobalScreenConfigurations()
                  └─> API Call: Common_Config_GetByIP

Location in ViewModel: /lib/view_models/screen_config_view_model.dart

Future<void> getGlobalConfigurationsByIP() async {
  GlobalConfigurationsModel? response = await screenDetailsRepo
      .getGlobalScreenConfigurations(ipAddress: currentScreenIP);
  // ...
}

❌ Current Issue: CORS

On Web:

✅ IP: 10.71.50.53 configured
✅ Initialization started
❌ API call blocked by browser CORS policy
❌ Error: ClientException: Failed to fetch

Why it fails on web:

  • Browser blocks the request to https://ms.hmg.com
  • Server doesn't have CORS headers configured
  • Same issue affects ALL API endpoints:
    • /PatientCallingHub (SignalR)
    • /api/PatientCall/Common_Config_GetByIP (Configuration)
    • /api/PatientCall/WeatherForecast_GetBy5Days (Weather)
    • /api/PatientCall/PrayerTime_Today (Prayer)
    • /api/PatientCall/RssFeed_Get (RSS Feed)
    • And all other REST APIs

Why it works on mobile:

  • Native apps don't have CORS restrictions
  • Only web browsers enforce CORS policy

📋 What Needs to Be Done

Backend team must:

  1. Add CORS configuration to ASP.NET Core app
  2. Apply CORS policy to ALL endpoints:
    • SignalR Hub
    • API Controllers
    • All routes under /api/*
  3. Test with browser console (see CORS_ISSUE_SOLUTION.md)

Complete instructions: See CORS_ISSUE_SOLUTION.md

🧪 How to Test Configuration API

In browser console:

fetch('https://ms.hmg.com/nscapi/api/PatientCall/Common_Config_GetByIP', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
        ipAddress: '10.71.50.53',
        apiKey: 'EE17D21C7943485D9780223CCE55DCE5'
    })
})
.then(r => {
    console.log('✅ Config API CORS working!');
    return r.json();
})
.then(data => console.log('Response:', data))
.catch(e => console.error('❌ Config API CORS blocked:', e));

Expected results:

  • ❌ Before CORS config: "Failed to fetch" error
  • ✅ After CORS config: JSON response with configuration data

📊 Summary

Component Status Notes
API Call Exists ✅ Yes In screen_details_repo.dart
Called on Startup ✅ Yes Via getGlobalConfigurationsByIP()
Works on Mobile ✅ Yes Native app, no CORS
Works on Web ❌ No Blocked by CORS
Error Handling ✅ Fixed Uncommented try-catch, added CORS detection
Solution ⚠️ Pending Backend needs CORS configuration

🎯 Next Steps

  1. Share CORS_ISSUE_SOLUTION.md with backend team
  2. Backend adds CORS headers to ALL API endpoints
  3. Test using browser console commands above
  4. Once working, deploy web app

Date: August 2, 2026
Status:

  • ✅ API call found and documented
  • ✅ Error handling improved
  • ⚠️ CORS configuration required for web deployment