Route 'api/lookup' not found on Nginx server (v2024)

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
luchidemus
User
Posts: 18

Route 'api/lookup' not found on Nginx server (v2024)

Post by luchidemus »

The file finds it, I get an error in jquery, but I get this error on my system: (locally it works)

"{\"statusCode\":404,\"error\":{\"class\":\"text-warning\",\"type\":\"Not Found\",\"description\":\"Route 'api\\/lookup' not found.\"}}"


arbei
User
Posts: 9603

Post by arbei »

The 'api/lookup' is a built-in route for API, make sure you have generated and upload all scripts, the routes definition files are generated under the <log>/cache/*RouteAttributes.php.

Do not ignore errors during script generation. If there are errors, for example, the *RouteAttributes.php are not generated successfully since you still use PHP 7, then there are no routes.

If you have enabled Use route cache, make sure you have deleted the old <log>/cache/*RouteCache.php.


luchidemus
User
Posts: 18

Post by luchidemus »

Is this the code that supposedly generates the api/lookup?

 /**
     * lookup
     */
    #[Map(["GET", "POST", "OPTIONS"], "/lookup[/{params:.*}]", [ApiPermissionMiddleware::class, JwtMiddleware::class], "lookup")]
    public function lookup(Request $request, Response $response, array $args): Response
    {
        global $Security, $Language;
        $this->setup($request, $response);
        if ($request->getContentType() == "application/json") { // Multiple requests
            $req = $request->getParsedBody();
            if (is_array($req)) { // Multiple requests
                $out = [];
                foreach ($req as $ar) {
                    if (is_string($ar)) { // Request is QueryString
                        parse_str($ar, $ar);
                    }
                    $object = $ar[Config("API_LOOKUP_PAGE")];
                    $fieldName = $ar[Config("API_FIELD_NAME")];
                    $res = [Config("API_LOOKUP_PAGE") => $object, Config("API_FIELD_NAME") => $fieldName];
                    $page = Container($object); // Don't use $this->container
                    $lookupField = $page?->Fields[$fieldName] ?? null;
                    if ($lookupField) {
                        $lookup = $lookupField->Lookup;
                        if ($lookup) {
                            $tbl = $lookup->getTable();
                            if ($tbl) {
                                $Security->loadTablePermissions($tbl->TableVar);
                                if ($Security->canLookup()) {
                                    $res = array_merge($res, $page->lookup($ar, false));
                                } else {
                                    $res = array_merge($res, ["result" => $Language->phrase("401")]);
                                }
                            }
                        }
                    }
                    if ($fieldName) {
                        $out[] = $res;
                    }
                }
                $response = $response->withJson(ConvertToUtf8($out));
            }
        } else { // Single request
            $page = $request->getParam(Config("API_LOOKUP_PAGE"));
            Container($page)?->lookup($request->getParams()); // Don't use $this->container
        }
        return $response;
    }

arbei
User
Posts: 9603

Post by arbei »

That is the api/lookup action. If you see that, the action is there. If it is not found, the route was not set up successfully.

arbei wrote:

make sure you have generated and upload all scripts, the routes definition files are generated under the <log>/cache/*RouteAttributes.php.
Do not ignore errors during script generation. If there are errors, for example, the *RouteAttributes.php are not generated successfully since you still use PHP 7, then there are no routes.

Make sure you find the *RouteAttributes.php under the log folder. Since you said it works locally on your PC, they should be there. Make sure you have uploaded them to your production server.

arbei wrote:

If you have enabled Use route cache, make sure you have deleted the old <log>/cache/*RouteCache.php.

If you have enabled Use route cache, also make sure the web server user has write permissions to the <log> folder and its subfolders.


luchidemus
User
Posts: 18

Post by luchidemus »

{statusCode: 404,…}
error
:
{class: "text-warning", type: "Not Found", description: "Route 'api/lookup' not found.",…}
statusCode
:
404

keep throwing that error. How can I generate that route, is phpmaker supposed to generate it? or does it have to be configured?


arbei
User
Posts: 9603

Post by arbei »

  1. Did you check the RouteAttributes.php, ApiRouteAttributes.php, RouteCache.php, ApiRouteCache.php files in the <log>/cache folder as said above? If not, open your FTP clients and check them (on the production server) as suggested first, don't skip.

  2. You MUST set write permission of the log folder, read Logging:
    1. ALWAYS specify a log file folder, it is not only used by log files but also used by cache files.
    2. Make sure that the web server user have read/write access to the folder. Unlike upload folder, this folder should be local. AWS S3 bucket should NOT be used.

  3. Make sure your production server has PHP >= 8.0.2.

  4. Make sure you have set up URL Rewrite for your production server correctly. If you use Apache, make sure you have uploaded the api/.htaccess to your server. If you use Nginx, make sure you have configured your server correctly.


luchidemus
User
Posts: 18

Post by luchidemus »

I have 2 in the logs folder.
routeattributes and apirouteattributes in production and locally,
What other possibility can it affect?
Thanks for your help in advance


arbei
User
Posts: 9603

Post by arbei »

arbei wrote:

If you have enabled Use route cache, make sure you have deleted the old <log>/cache/*RouteCache.php (namely, RouteCache.php and ApiRouteCache.php)

If you have enabled Use route cache, also make sure the web server user has write permissions to the <log> folder and its subfolders (so the RouteCache.php and ApiRouteCache.php can be created)

Note that the existence of RouteAttributes.php and ApiRouteAttributes.php under the log folder does not necessarily mean you have write permission because these two files are generated by PHPMaker after generation and you uploaded them. However, if you have enabled Use route cache, the RouteCache.php and ApiRouteCache.php are created by PHP scripts on your server, so the web server user must have write permissions to the log folder and its subfolder (i.e. "<log>/cache").

And as said above: (Since you said it works locally, so it should be something on your server)

  1. Make sure your production server has PHP >= 8.0.2.
  2. Make sure you have set up URL Rewrite for your production server correctly. If you use Apache, make sure you have uploaded the .htaccess and api/.htaccess to your server. If you use Nginx, make sure you have configured your server correctly.

luchidemus
User
Posts: 18

Post by luchidemus »

I just found out that I am uploading it to an ngnix server, how can to configure my project for the same?
From my project do I have to configure it or do I have to ask those responsible for the server to configure it?


arbei
User
Posts: 9603

Post by arbei »

You need to set up the Nginx virtual host configuration, see URL Rewrite -> Nginx.


luchidemus
User
Posts: 18

Post by luchidemus »

I already have the server configured in an older version of phpmaker (2011) and now I want to move to 2024, do I have to make any changes to gnix?


Webmaster
User
Posts: 9435

Post by Webmaster »

Routing was introduced in v2021, you need to configure URL Rewrite for routing to work.


Post Reply