代码之家  ›  专栏  ›  技术社区  ›  Kaleb Brasee

禁用grails可搜索插件默认搜索页?

  •  5
  • Kaleb Brasee  · 技术社区  · 15 年前

    我正在尝试禁用可搜索插件默认搜索页( http://localhost/searchable/ ),但还没找到办法。有人知道如何做到这一点,最好是以合法的方式,但诉诸欺骗,如果必要的话?

    1 回复  |  直到 15 年前
        1
  •  4
  •   Burt Beckwith    15 年前

    class UrlMappings {
    
       static mappings = {
    
          "/searchable/$action?"(controller: "errors", action: "urlMapping")
    
          "/$controller/$action?/$id?" { }
    
          "/"(view:"/index")
    
          "403"(controller: "errors", action: "accessDenied")
          "404"(controller: "errors", action: "notFound")
          "405"(controller: "errors", action: "notAllowed")
          "500"(view: '/error')
       }
    }
    

    其中ErrorsController看起来像这样:

    class ErrorsController {
    
       def accessDenied = {}
    
       def notFound = {
          log.debug "could not find $request.forwardURI"
       }
    
       def notAllowed = {}
    
       def urlMapping = {
          log.warn "unexpected call to URL-Mapped $request.forwardURI"
          render view: 'notFound'
       }
    }
    

    您需要在grails app/errors中创建accessDenied.gsp、notFound.gsp和notAllowed.gsp

    通过将“隐藏”控制器发送到其自定义映射,您可以记录对它的意外访问,但仍然呈现404页以隐藏其存在。