找不到resources.json [英] Can't find resources.json

查看:138
本文介绍了找不到resources.json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因,当我使用Restler的API资源管理器(Swagger UI的一个分支)将API部署到生产环境时,加载时会出现一般404错误:

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

当我更明确地陈述时:

/api/explorer/index.html

它将加载页面的框架,但是在标题下方的红色文本中报告"404:未找到../resources.json":

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

我可以肯定的是,在本地运行相同的文件时,环境中会散布些东西.我还检查了/api/explorer目录中的.htaccess文件,它对我来说很合适:

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>

任何帮助将不胜感激.

推荐答案

事实证明,所有问题都归结为mod_rewrite问题.我仍然不是100%为何会在一个环境中出现此问题,但是在完全相同的httpd.conf.htaccess的其他环境中却没有出现.哦,好了,解决方法是使用RewriteBase指令在有关基本URL的重写规则中明确规定.

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.

在API目录中,我现在有以下.htaccess文件:

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>

在API-Explorer目录中,我现在具有以下.htaccess:

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>

为了解决此问题,我遇到的一个宝贵建议是打开Apache的mod_rewrite日志记录.

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

将此内容放置在httpd.conf的任何全局范围内的区域;我把它放在已经存在的有关日志的条目周围,但是如果您愿意的话,也可以将其放在结尾.此外,有关重写故障排除的基础知识还包括(如果很抱歉,则表示歉意):

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. 确保为服务Restler的目录的httpd.conf设置了AllowOverride AllOptions FollowSymLinks.
  2. 您可以将所有配置放入httpd.conf中,并完全避免使用.htaccess文件(这样做也更快一些),但是如果您这样做,请记住httpd.conf.htaccess具有绝对的URL引用.的亲戚.
  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.

这篇关于找不到resources.json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆