2

I am using grails 3.2.7. Can anyone please tell me how to prevent Interceptor to intercept static resources?

it's currently intercepting

<script src="/appName/js/apps/file.js"></script>

as

controllerName == js, actionName == apps, params == [controller:js, action:apps, id:file.js]

can anyone help me with a way to prevent such interception. I want my Interceptor should only work for controller, actions. Not for static resources.

Charu Jain
  • 852
  • 1
  • 7
  • 18
  • That sounds like a bug. If you file an issue at https://github.com/grails/grails-core/issues and link to a sample app which demonstrates the problem, we can get it straightened out. Thanks for the feedback. – Jeff Scott Brown Aug 16 '17 at 13:30
  • Hi @JeffScottBrown Seems like this was intentionally done with https://github.com/grails/grails-core/issues/9724 But I have certain code in my interceptor that should only work when it hit any controller, action. – Charu Jain Aug 16 '17 at 16:22
  • @JeffScottBrown: I have created the question at https://github.com/grails/grails-core/issues/10779 Please check.Thanks! – Charu Jain Aug 17 '17 at 10:53
  • I think the change was intentional. Sorry for the trouble. – Jeff Scott Brown Aug 17 '17 at 13:07
  • @JeffScottBrown But is there a way to prevent such interception to static resource ? – Charu Jain Aug 17 '17 at 13:53
  • "But is there a way to prevent such interception to static resource ?" - Yes. One way to do that is to only match requests to certain controllers. – Jeff Scott Brown Aug 17 '17 at 14:04
  • 3
    We are discussing adding something like `matchAllControllers()` in addition to `matchAll()`. – Jeff Scott Brown Aug 17 '17 at 14:04

2 Answers2

0

Not ideal, but what works is excluding uris that hold the static content e.g. like so in the constructor of an interceptor

RobotsInterceptor() {
    matchAll().except(uri: '/js/**')
            .except(uri: '/css/**')
            .except(uri: '/icons/**')
            .except(uri: '/images/**')
            .except(uri: '/fonts/**')
            .except(uri: '/static/**')
            .except(uri: '/asset-manifest.json')
            .except(uri: '/fav.ico')
}
Ev0oD
  • 1,395
  • 16
  • 33
0

Try calling that library like this:

<g:javascript src="/appName/js/apps/file.js"/>
MKOCH
  • 45
  • 1
  • 5