Grails 2 does not serve static resources

I am using Grails 2.0.4 and would like to serve some static resources like images or videos.

I have a png version of the grails logo in images / grails_logo.png (as usual). If I type the URL "http: // localhost: 8080 / TmmWeb / static / images / grails_logo.png", it will show me this logo.

But if I add "http: // localhost: 8080 / TmmWeb / static / images / grails_logo.jpg" (there is also a jpeg version of the old logo), the application shows a 404 report that "The requested resource () is unavailable.".

If I create a "video" subdirectory and change the configuration line for adhoc templates as grails.resources.adhoc.patterns = ['/images/*', '/css/*', '/js/*', '/plugins/*','/videos/*'] , then the URL "http: // localhost: 8080 / TmmWeb / static / images / grails_logo.png" also fails to cope with this complaint.

If I found that adhoc templates are set to null using grails.resources.adhoc.patterns = [] , then URLs such as "http: // localhost: 8080 / TmmWeb / videos / grails_logo.png" work and deliver content

So why, when using adhoc filters, only .png files can be sent from the image directory, and not from the video directory, and that .jpg files cannot be sent?

Because these URLs do not work, using these URLs also fails to embed images or videos on the page.

I should also note that ultimately I want to have access to the entire video directory without entering each of them into a resource declaration.

+4
source share
1 answer

The answer here turned out to be rather complicated. The new version of the Resources 1.2 plugin contains a full explanation in the user guide.

In short, elements allowed by special filters will receive a redirect response to the corresponding element in the / static URI.

Any files in the base directory of the web application will be served in the appropriate place in the web space / static URI, even if they are not specified in the ad-hoc template filters.

This behavior will be true for 1.1.x and 1.2 versions of the Resources plugin. This does not apply to the version of Grails used.

+1
source

Source: https://habr.com/ru/post/1433256/


All Articles