播放路由配置完全忽略Http OPTIONS请求

 yangjiao1985 发布于 2023-02-11 14:27

我正在使用Play 2.2.1.我的路由文件中有以下路由配置:

OPTIONS       /*path          controllers.Application.options
GET           /               controllers.Application.index
...some more routes

我在Applications控制器中进行了以下设置:

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请求时,它会被播放完全忽略.

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





    
        Action not found

...some more head junk

    
        

Action not found

For request 'OPTIONS /foo/139'

These routes have been tried, in this order:

1GET/controllers.Application.index
... more routes but none of them are for the OPTIONS request

我在这做错了什么?提前致谢!

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有