Nginx config rule to invoke an API before a rule

My web application has an Nginx rule according to which ^/([^/?&:'"]+)$ will resolve to an HTML file. For example, /example URI will resolve to index.html. Now I wanted to write a rule that we call an API before resolving to an HTML file. If that API returns true (200 OK), we resolve it with the file; otherwise, 404.

I have an Nginx configuration where I have a block as below.

root /usr/share/jitsi-meet;


location ~ ^/([^/?&:'"]+)$ {
    try_files $uri @root_path;
}

Please find below the desired pseudo code.

location ~ ^/([^/?&:'"]+)$ {
  if(callAPI){
      try_files $uri @root_path;
  }else{
      //redirect to 404 page
  }
    
}
How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum