找不到resources.json

找不到resources.json

问题描述:

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.

出于某种原因,当我使用Restler的API Explorer(Swagger UI的分支)将API部署到生产时,它给了我 加载时出现一般性的404错误: p>

  / api / explorer 
  code>  pre> 
 
 

当我更加明确和陈述时 : p>

  /api/explorer/index.html
  code>  pre> 
 
 

它加载页面的框架但随后报告 标题下方红色文字中的“404:Not Found ../resources.json”: p>

p>

我很确定环境会因为本地相同的文件而起作用。 我还检查了 / api / explorer code>目录中的.htaccess文件,它看起来对我来说: p>

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

任何帮助都将不胜感激。 p> div>

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.

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

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...

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