12c80e276f91d0920d4c39e76870745a69e19b4d
braney
  Mon Jan 9 16:47:40 2023 -0800
add support for curated hubs to hubApi

diff --git src/hg/hubApi/hubApi.c src/hg/hubApi/hubApi.c
index 46d2308..73cf62c 100644
--- src/hg/hubApi/hubApi.c
+++ src/hg/hubApi/hubApi.c
@@ -1236,30 +1236,41 @@
 //    cgiMakeHiddenVar("debug", "1");
 }
 
 static void apiRequest(char *pathInfo)
 {
 hPrintDisable();
 /*expect no more than MAX_PATH_INFO number of words*/
 char *words[MAX_PATH_INFO];
 /* can immediately verify valid parameters right here right now */
 char *start = cgiOptionalString("start");
 char *end = cgiOptionalString("end");
 char *db = cgiOptionalString("genome");
 char *hubUrl = cgiOptionalString("hubUrl");
 struct dyString *errorMsg = dyStringNew(128);
 
+// first check for curated hubs
+if (isEmpty(hubUrl) && isNotEmpty(db))
+    {
+    char *newHubUrl;
+    if (hubConnectGetCuratedUrl(db, &newHubUrl))
+        {
+        hubUrl = newHubUrl;  // use curated hub hubUrl
+        cgiVarSet("hubUrl", hubUrl);   // subsequent code grabs hubUrl from env
+        }
+    }
+
 if (isEmpty(hubUrl) && isNotEmpty(db))
     {
     struct sqlConnection *conn = hAllocConnMaybe(db);
     if (NULL == conn)
         dyStringPrintf(errorMsg, "can not find genome genome='%s' for endpoint '%s'", db, pathInfo);
     else
         hFreeConn(&conn);
     }
 if (isNotEmpty(start) || isNotEmpty(end))
     {
     long long llStart = -1;
     long long llEnd = -1;
     struct errCatch *errCatch = errCatchNew();
     if (errCatchStart(errCatch))
         {
@@ -1571,31 +1582,34 @@
     sleep1000(botDelay);
     }
 
 setGlobalCgiVars();
 
 #ifdef NOTUSED // the argument processing doesn't allow udcTimeout
 int timeout = cgiOptionalInt("udcTimeout", 300);
 if (udcCacheTimeout() < timeout)
     udcSetCacheTimeout(timeout);
 #endif
 setUdcCacheDir();
 
 initSupportedTypes();
 
 char *pathInfo = getenv("PATH_INFO");
+char *cmd;
 if (isNotEmpty(pathInfo)) /* can get to this immediately, no cart needed */
     apiRequest(pathInfo);
+else if ((cmd = cgiOptionalString("cmd")) != NULL)
+    apiRequest(cmd);
 else
     {
     char *allowApiHtml = cfgOptionDefault("hubApi.allowHtml", "off");
     if (sameWord("on", allowApiHtml))
 	{
 	trackCounter = hashNew(0);
 	cartEmptyShellNoContent(doMiddle, hUserCookie(), excludeVars, oldVars);
 	}
     else
 	redirectToHelp();
     }
 cgiExitTime("hubApi", enteredMainTime);
 return 0;
 }