mikespub-org / seblucas-cops

Calibre OPDS (and HTML) PHP Server : web-based light alternative to Calibre content server / Calibre2OPDS to serve ebooks (epub, mobi, pdf, ...)
http://blog.slucas.fr/en/oss/calibre-opds-php-server
GNU General Public License v2.0
55 stars 7 forks source link

restapi.php broken in 2.1.4 #74

Closed bcleonard closed 4 months ago

bcleonard commented 4 months ago

restapi.php is broken starting with release 2.1.4 (I suspect it was 2.1.3, but that was unreleased).

I noticed it when my homepage link using the api broke after the upgrade to 2.3.1.

When accessing /restapi.php, I get the following error: Fetch error Not Found /restapi.php/openapi

Please see the attached screenshots for a working/not-working.

cops_notworking cops_working

I suspect that the openapi stuff has not been fully implemented. If that is the case, I recommend that you roll back the changes until its fully baked.

mikespub commented 4 months ago

Hi @bcleonard thanks for the feedback. You may be the first besides myself to comment on this :-)

The REST API is something fairly new and it only works in dev mode since version 2.x, i.e. if you install COPS with all the required dev packages in composer.json

From my perspective the /restapi.php/openapi URL works fine, as you get a functional Swagger UI interface with all the APIs working properly when you try /restapi.php since version 2.1.4.

Of course, that's assuming you do have a working base URL for your installation. For example, in my Ubuntu wsl2 distribution I have a symlink from the COPS source repo to /var/www/html/cops with /var/www/html served with Apache, and I can access the REST API via http://localhost/cops/restapi.php for development, and similarly from my Synology NAS in production.

Does that help at all?

mikespub commented 4 months ago

Hmm, actually never mind the dev mode - I moved nikic/fast-route to production around version 2.1.3 already.

The comment on the working base URL remains though, and yes, the functionality has changed a bit since the initial 1.3.6 release - sorry for the confusion.

The equivalent of the old restapi.php would now be restapi.php/index

Screenshot 2024-02-26 100532

mikespub commented 4 months ago

Note: if you have a setup that requires the use of $config['cops_full_url'] this will now be used in restapi.php in release 2.4.1

/*
 * Full URL prefix (with trailing /)
 * useful especially for Opensearch where a full URL is often required
 * For example Mantano, Aldiko and Marvin require it.
 */
$config['cops_full_url'] = '';
mikespub commented 4 months ago

Hi @bcleonard with the input above were you able to fix your homepage link?

bcleonard commented 4 months ago

sorry, been way to busy the last week. I had a chance to test it this morning. I'm still not able to get the either the original api nor your new openapi url.

original_api_Screenshot 2024-03-04 112545

openapi_Screenshot 2024-03-04 112625

I pulled 2.4.1. I'm not using cops_full_url

mikespub commented 4 months ago

With nginx in front of the COPS site, you probably need to double-check if it is configured to support PATH_INFO first - see https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/

Then you may need to specify cops_full_url now in order to get the right absolute URLs instead of the relative URLs it used in older versions.

Once they're configured to reflect how you set up your environment, you should be good to go for all future versions :-)

bcleonard commented 4 months ago

PATH_INFO was the issue. Once I enabled that, i can now get to the old restapi via /restapi.php/index.

BTW, I did not need to set cops_full_url

cops_working_restapi_openapi_Screenshot 2024-03-04 152535

cops_working_restapi_original_Screenshot 2024-03-04 152450

mikespub commented 4 months ago

Glad it worked out :-)

BTW, if the PATH_INFO hadn't worked out, only a few /restapi.php/ paths are specific to the REST API itself.

For all standard COPS pages you could always fall back to using the old getJSON.php?page=... syntax too :-)