FIX API return 404 sometimes even if API exists
This commit is contained in:
parent
8241bc414a
commit
e92c6c87a0
@ -88,17 +88,22 @@ if (preg_match('/api\/index\.php\/explorer/', $_SERVER["PHP_SELF"]) && ! empty($
|
|||||||
// index.php/xxx called by any REST client to run API
|
// index.php/xxx called by any REST client to run API
|
||||||
|
|
||||||
|
|
||||||
|
$reg=array();
|
||||||
preg_match('/index\.php\/([^\/]+)(.*)$/', $_SERVER["PHP_SELF"], $reg);
|
preg_match('/index\.php\/([^\/]+)(.*)$/', $_SERVER["PHP_SELF"], $reg);
|
||||||
// .../index.php/categories?sortfield=t.rowid&sortorder=ASC
|
// .../index.php/categories?sortfield=t.rowid&sortorder=ASC
|
||||||
|
|
||||||
|
|
||||||
// Set the flag to say to refresh (when we reload the explorer, production must be for API call only)
|
// Set the flag to say to refresh (when we reload the explorer, production must be for API call only)
|
||||||
$refreshcache=false;
|
/*$refreshcache=false;
|
||||||
if (! empty($reg[1]) && $reg[1] == 'explorer' && ($reg[2] == '/swagger.json' || $reg[2] == '/swagger.json/root' || $reg[2] == '/resources.json' || $reg[2] == '/resources.json/root'))
|
if (! empty($reg[1]) && $reg[1] == 'explorer' && ($reg[2] == '/swagger.json' || $reg[2] == '/swagger.json/root' || $reg[2] == '/resources.json' || $reg[2] == '/resources.json/root'))
|
||||||
{
|
{
|
||||||
$refreshcache=true;
|
$refreshcache=true;
|
||||||
}
|
}*/
|
||||||
|
// When in production mode, a file api/temp/routes.php is created with the API available of current call.
|
||||||
|
// But, if we set $refreshcache to false, so it may have only one API in the routes.php file if we make a call for one API without
|
||||||
|
// using the explorer. And when we make another call for another API, the API is not into the api/temp/routes.php and a 404 is returned.
|
||||||
|
// So we force refresh to each call.
|
||||||
|
$refreshcache=true;
|
||||||
|
|
||||||
$api = new DolibarrApi($db, '', $refreshcache);
|
$api = new DolibarrApi($db, '', $refreshcache);
|
||||||
//var_dump($api->r->apiVersionMap);
|
//var_dump($api->r->apiVersionMap);
|
||||||
@ -115,7 +120,7 @@ UploadFormat::$allowedMimeTypes = array('image/jpeg', 'image/png', 'text/plain',
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Call Explorer file for all APIs definitions
|
// Call Explorer file for all APIs definitions (this part is slow)
|
||||||
if (! empty($reg[1]) && $reg[1] == 'explorer' && ($reg[2] == '/swagger.json' || $reg[2] == '/swagger.json/root' || $reg[2] == '/resources.json' || $reg[2] == '/resources.json/root'))
|
if (! empty($reg[1]) && $reg[1] == 'explorer' && ($reg[2] == '/swagger.json' || $reg[2] == '/swagger.json/root' || $reg[2] == '/resources.json' || $reg[2] == '/resources.json/root'))
|
||||||
{
|
{
|
||||||
// Scan all API files to load them
|
// Scan all API files to load them
|
||||||
@ -253,5 +258,6 @@ if (! empty($reg[1]) && ($reg[1] != 'explorer' || ($reg[2] != '/swagger.json' &&
|
|||||||
//var_dump($api->r->apiVersionMap);
|
//var_dump($api->r->apiVersionMap);
|
||||||
//exit;
|
//exit;
|
||||||
|
|
||||||
// Call API (we suppose we found it)
|
// Call API (we suppose we found it).
|
||||||
|
// The handle will use the file api/temp/routes.php to get data to run the API. If the file exists and the entry for API is not found, it will return 404.
|
||||||
$api->r->handle();
|
$api->r->handle();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user