Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails Routes - ignore css, js and images

How do you get UrlMappings to ignore /css, /js and /images when you have added a route like this

UPDATE

"$username"(controller:"profile",action:"show") {
        constraints {
            username(notInList:['css','js','images'])
        }
}

Can I use notInList? I how do I reverse inList?

like image 733
BuddyJoe Avatar asked Feb 23 '23 08:02

BuddyJoe


1 Answers

From the manual:

If you are using wildcard URL mappings then you may want to exclude certain URIs from Grails' URL mapping process. To do this you can provide an excludes setting inside the UrlMappings.groovy class:

class UrlMappings = {
    static excludes = ["/images/*", "/css/*"]
    static mappings = {
        …
    }
}

This allows you to exclude directories from the mapping.

Update If you want to use a regex, this might work better:

constraints {
    username(matches:"^(?!(js|css|images)/).*")
}

This regex matches anything that doesn't start with js/, css/, or images/. It matches via zero-width negative lookahead ((?!…).

like image 87
OverZealous Avatar answered Mar 05 '23 15:03

OverZealous