0

For some reason when I deploy my API using Restler's API Explorer (a fork of Swagger UI) to production it gives me a general 404 error when I load:

/api/explorer

When I am more explicit and state:

/api/explorer/index.html

It loads the framing for the page but then reports "404 : Not Found ../resources.json" in red text below the header:

enter image description here

I'm fairly certain there's something environmental flaring up as the same files locally work. I also checked the .htaccess file in the /api/explorer directory and it looks right to me:

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

Any help would be appreciated.

leppie
  • 115,091
  • 17
  • 196
  • 297
ken
  • 8,763
  • 11
  • 72
  • 133

4 Answers4

2

It turns out all the problems were down to a mod_rewrite problem. I'm still not 100% on WHY this problem showed up in one environment but not others with precisely the same httpd.conf and .htaccess. Oh well, the solution is to be explicit in the rewrite rule about your base url using the RewriteBase directive.

In the API directory I now have the following .htaccess file:

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

In the API-Explorer directory I now have the following .htaccess:

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

In order to troubleshoot this problem one invaluable tip that I came across is turning on Apache's mod_rewrite logging.

# Adding logging for Rewrites
RewriteLog logs/rewrite.log
RewriteLogLevel 2

Put this in any globally scoped area of httpd.conf; I put it around the entries that were already there about logging but you can also just put it at the end if you like that better. In addition, the basics around rewrite troubleshooting includes (apologies if this basic):

  1. make sure that your httpd.conf has AllowOverride All and Options FollowSymLinks set for the directories you serving Restler out of.
  2. You can put all of the configuration into httpd.conf and avoid .htaccess files altogether (and it's a bit faster that way too) but if you do that remember that httpd.conf has absolute url referencing versus .htaccess's relative.
ken
  • 8,763
  • 11
  • 72
  • 133
  • note: I have set RewriteLogLevel to 2 as that give useful information without being too chatty. – ken Feb 11 '13 at 19:35
0

You can check the ReadMe file on the Restler Github page https://github.com/Luracast/Restler-API-Explorer#readme

  • What specifically? I've looked at the README many times but as my wife will tell you I sometimes can't see what's right in front of me. – ken Feb 05 '13 at 22:17
0

Did you add the 'Luracast\Restler\Resources' class to create resources.json at API Root?

In your own index.php, the addAPIClass section should look like this:

$r = new Restler();

$r->addAPIClass('Luracast\\Restler\\Resources'); //this creates resources.json at API Root

// ... your own addApiClass

$r->handle();

It is in the documentation under "Use", but I had trouble figuring this out as well...

Community
  • 1
  • 1
Jelle
  • 1,024
  • 10
  • 18
  • Yes I've done this. In fact the same files (both in the /restler as well as the /api directories) work fine for me in my development environment for my desktop but do NOT work (aka, with error above) in both production and my laptop environment (which paradoxically is mirrored from the working dev environment using dropbox). – ken Feb 08 '13 at 07:27
0

Make sure you have cache directory with write permission in your api root

int
  • 13
  • 4