Serving static resources with Micronaut, with directory hierarchy

Viewed 1439

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

1 Answers

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

  router:
    static-resources:
      default:
        paths: 
          - file:/root/static
        mapping: /static/**/*
        enabled: true
Related