微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用apache和windows为Backbone.js设置一个RESTful服务

我正在尝试在我的apache本地主机上设置一个RESTful Web服务,作为我的主干应用程序的后端。 我努力了:

设置WebDAV,但在日志中获取以下错误消息

[Thu Feb 23 21:46:17 2012] [error] [client 127.0.0.1]无法为/ clusters / 19放置新内容。 [403,#0],referer: http://ideas.localhost/ [Thu Feb 23 21:46:17 2012] [error] [client 127.0.0.1]打开资源时发生错误。 [500,#0],引用者: http://ideas.localhost/

使用Backbone.emulateHTTP,这将导致405 method not allowed error (我猜是由X-HTTP-Method-Override: PUT头引起的,因为正常的POST请求工作正常

用于Slim Framework API路由的Nginxconfiguration

Nginx位置configuration(子文件夹)

我在Windows 7上运行Apache 2.2.21和PHP 5.3,下面是我的.htaccess文件。 我也使用SLIM框架来处理url路由。

RewriteEngine On RewriteBase / RewriteRule ^index.PHP$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.PHP [L]

和虚拟主机configuration

<VirtualHost *:80> DocumentRoot "G:/sites/ideas" Dav On // I also had security setting set to Allow all as it's just my localhost ServerName ideas.localhost ErrorLog "logs/ideas.localhost-error.log" CustomLog "logs/ideas.localhost-access.log" combined SetEnv APPLICATION_ENV development </VirtualHost>

我一直在努力争取一些年龄的工作,所以任何帮助不胜感激。

不能相信我在开奖之后不到一个小时就解决了这个问题,但嘿嘿。

问题在于Slim没有内置的能力来处理主干所使用的X-HTTP-Method-Override头,这个错误信息不是非常具有描述性。 在request.PHP底部添加以下内容,并在Backbone中使用emulateHTTP模式修复它

protected function checkForHttpMethodoverride() { if ( isset($this->post[self::METHOD_OVERRIDE]) ) { $this->method = $this->post[self::METHOD_OVERRIDE]; unset($this->post[self::METHOD_OVERRIDE]); if ( $this->isPut() ) { $this->put = $this->post; } } else if(isset($this->headers['x-method-override'] )) { $this->method = $this->headers['x-method-override']; if ( $this->isPut() ) { $this->put = $this->post; } } }

PS – 我已经创建了SLIM的拉取请求 ,包括这个,所以如果你觉得把它包含在框架中是一个好主意,请在那里留言

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐