mevdschee / php-crud-api

Single file PHP script that adds a REST API to a SQL database

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error code :1000, message : Route not found

Ghenimi opened this issue · comments

Hello,

I have completed a project using this API in my local machine, and all the work is centered around it. It required a lot of time and effort from me. but when i have transferted the project to deployment to an online server as production process, I have got a serious error; for any API request it shows :

{"code":1000,"message":"Route '\/api\/records\/any_table_any_map' not found"}

I have multiple WordPress and Joomla CMS installations on the same server, and all are functioning well. Also, I have tested the database connection parameters and executed several SQL queries, all the replies are successful. The error is likely stemming from the .htaccess configuration or mod_rewrite.c because when I make the .htaccess file as described in:
https://github.com/mevdschee/php-crud-api?tab=readme-ov-file#pretty-url :

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ api.php [QSA,L]
</IfModule>

the error is :
File not found.
I tried to remove the IfModule mod_rewrite like this :

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ api.php [QSA,L]

it successfully reads the api.php file, even when I include some echo statements in the api.php file, it displays the expected content. However, the error is :
{"code":1000,"message":"Route '\/api\/records\/any_table_any_map' not found"}

If you want to know more about the server configuration :

PHP Version : 8.2.10
Build System : Linux d73abf0b4d30 5.10.0-25-cloud-amd64 #1 SMP Debian 5.10.191-1 (2023-08-16) x86_64 GNU/Linux
Server API : FPM/FastCGI
Virtual Directory Support : disabled
Apache 2.0 Handler : Ian Holsman, Justin Erenkrantz (based on Apache 2.0 Filter code)
CGI / FastCGI : Rasmus Lerdorf, Stig Bakken, Shane Caraveo, Dmitry Stogov

If you require additional information about the server, I am happy to provide it. Any insights or guidance on debugging this discrepancy would be greatly appreciated.

Thank you.

Hi, Thank you for (more) thorough explanation. I think you need to set the "basePath" config parameter to "/api/". Let me know how that works for you. Kind regards, Maurits

Hi Maurits,

Thank you for your suggestion! Setting the "basePath" in $config parameters to "/api/" resolved the routing issue! Everything is working perfectly. I appreciate your prompt assistance!

Just a thought for consideration: Making the "basePath" parameter dynamic could provide users with more flexibility, especially in scenarios where the API might be deployed in different environments with varying base paths.

Thanks again for your assistance!

Best regards,
Khalil