5

Given the following configuration in application.yml, I would expect to be able to serve files from both of the following paths:

  • http://localhost/static/image.png (from /root/static/image.png)
  • http://localhost/static/folder/image.png (from /root/static/folder/image.png)

However, only the first path works. The second returns a 200 status code with the following in the response body: {"message":"Page Not Found","_links":{"self":{"href":"/static/folder/image.png","templated":false}}}

The issue seems to be the extra subdirectory, but I would have expected the **/* in the mapping field to allow for subdirectories. FWIW, I get the same error if I request a resource that does not exist.

This is on Micronaut 2.

micronaut:
  application:
    name: api
  router:
    static-resources:
      default:
        paths: file:/root/static
        mapping: /static/**/*
        enabled: true

psyklopz
  • 2,283
  • 4
  • 24
  • 29
  • 2
    `**/*` does work for me the way you expect it to (micronaut version 2.1.4), so I suspect the problem might be somewhere else. Keep in mind if the "folder" directory or the file you're trying to access within it are not accessible to the micronaut process due to OS-level permissions, you will get the error you got. – Diego Veralli Nov 19 '20 at 16:04
  • Ah! Sometimes you can't see the forest through the trees. My "folder" was named `v1_0_1` and I was trying to download it with `v_1_0_1` in the URL. I was so convinced it was something in the config file. Thanks, Diego for getting me to think outside of the Java box. – psyklopz Nov 19 '20 at 20:35

1 Answers1

2

The paths key should be a list (as hinted by the plural):

  router:
    static-resources:
      default:
        paths: 
          - file:/root/static
        mapping: /static/**/*
        enabled: true
Robert Jack Will
  • 10,333
  • 1
  • 21
  • 29