Http OPTIONS 请求被 Play 路由配置完全忽略 [英] Http OPTIONS request gets completely ignored by Play route config
本文介绍了Http OPTIONS 请求被 Play 路由配置完全忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是 Play 2.2.1.我的路由文件中有以下路由配置:
I'm using Play 2.2.1. I have the following route configuration in my route file:
OPTIONS /*path controllers.Application.options
GET / controllers.Application.index
...some more routes
我在应用程序控制器中设置了以下内容:
I have the following set up in the Applications controller:
package controllers
import play.api.mvc._
object Application extends Controller {
def index = Action {
Ok(views.html.index())
}
def options = Action {
Ok("").withHeaders(
"Access-Control-Allow-Origin" -> "*",
"Access-Control-Allow-Methods" -> "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers" -> "Accept, Origin, Content-type, X-Json, X-Prototype-Version, X-Requested-With",
"Access-Control-Allow-Credentials" -> "true",
"Access-Control-Max-Age" -> (60 * 60 * 24).toString
)
}
}
当我尝试使用 curl 测试 OPTIONS 请求时,它被游戏完全忽略了.
When I try to test an OPTIONS request with curl, it gets completely ignored by play.
curl -X OPTIONS --include 'http://localhost:9000/foo/139'
我又恢复了这个错误:
HTTP/1.1 404 Not Found
Content-Type: text/html; charset=utf-8
Content-Length: 7045
<!DOCTYPE html>
<html>
<head>
<title>Action not found</title>
...some more head junk
<body>
<h1>Action not found</h1>
<p id="detail">
For request 'OPTIONS /foo/139'
</p>
<h2>
These routes have been tried, in this order:
</h2>
<div>
<pre><span class="line">1</span><span class="route"><span class="verb">GET</span><span class="path">/</span><span class="call">controllers.Application.index</span></span></pre>
... more routes but none of them are for the OPTIONS request
我在这里做错了什么?提前致谢!
What am I doing wrong here? Thanks in advance!
推荐答案
Do something with *path
段 - 即使什么都不做...
Do something with *path
segment - even if nothing...
路线:
OPTIONS / controllers.Application.options(path: String ?= "")
OPTIONS /*path controllers.Application.options(path)
操作:
def options(path: String) = Action {
Ok("").withHeaders(
"Access-Control-Allow-Origin" -> "*",
"Access-Control-Allow-Methods" -> "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers" -> "Accept, Origin, Content-type, X-Json, X-Prototype-Version, X-Requested-With",
"Access-Control-Allow-Credentials" -> "true",
"Access-Control-Max-Age" -> (60 * 60 * 24).toString
)
}
有效
这篇关于Http OPTIONS 请求被 Play 路由配置完全忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文