How to set up Grails 3 UrlMappings.groovy file so that there is no default url mapping? -
i have issue i'm facing while upgrading grails 2 grails 3. in grails 2 project, had urlmappings.groovy file looked this:
class urlmappings { static mappings = { //"/$controller/$action?/$id?(.$format)?"{ // parserequest = false // constraints { // apply constraints here // } //} "/$controller/$id" { action = [get: "show", put: "update", delete: "delete"] constraints { // constrain id numeric, uncomment following: //id matches: /\d+/ } } "/$controller/$action" { constraints { action matches: /external.*/ } } "/$controller" { action = [get: "list", post: "create"] parserequest = true } "/$controller/$action/$id" { } "/$controller/search" { action = [post: "search"] parserequest = true } "/$controller/count" { action = [get: "count"] } "/"(view:"/index") "500"(controller: 'error') } } this worked automatically hit action when format of url used (e.g. http://localhost:8090/api/test hit testcontroller's list action).
in new grails 3 project, have moved mappings correct location (grails-app/controllers/my.project.package), , package specified @ top of file. want behavior stay same specified in example above. however, see internal server error when hit endpoint now.
i believe receive internal server error because testcontroller not have index action in , url http://localhost:8090/api/test trying hit index action instead of list action.
i have generated url mappings report both new , old projects, , see grails 3 project's url mappings report contains default url mapping ( | * | /${controller}/${action}?/${id}?(.${format)? | action: (default action) |) though commented out in url mapping. still generated after performing clean , removing commented out bit urlmappings.groovy file. default mapping issue? if so, there way stop app using it?
one thing have tried using constraint controller(validator: { return false }) in constraints block of mapping "/$controller/$action?/$id?(.$format)?". thing have tried using different format custom url mappings like
get "/$controller/$id"(action: "show") put "/$controller/$id"(action: "update") delete "/$controller/$id"(action: "delete") "/$controller"(action: "list") post "/$controller"(action: "create") post "/$controller/search"(action: "search") "/$controller/count"(action: "count") unfortunately, did not have luck either of these solutions. did have luck using static controller names (e.g. "/test" { controller = "test", action = [get: "list", post: "create"] }), have many different controllers isn't great me.
please let me know if has worked around or solved issue. appreciate it!
Comments
Post a Comment