I want to serve static resources with path params in the URLs.
I am providing the following configuration in the yml:
```
micronaut:
router:
static-resources:
default:
enabled: true
mapping: /pr/{id}
paths:
- classpath:web/public
### Expected Behaviour
After building the application along with the React app, lets say I launch the application at - https://host:xxxx/pr/10
I expect my React app to be loaded at the given url with index page and path param having a value 10 (which in my case, I am using inside React Route).
### Actual Behaviour
Unfortunately, this doesn't seem to happen and there is an error message on the UI - {"message":"Page Not Found","_links":{"self":{"href":"/pr/10","templated":false}}}
### Environment Information
- **Micronaut Version:** 1.2
### Some debugging information
I digged inside a little and found that the path and mapping fail to match according to the match provided by the path matcher being used(`AntPathMatcher`). I have verified this using the following test code:
AntPathMatcher antPathMatcher = new AntPathMatcher();
boolean matches = antPathMatcher.matches("/pr/{id}", "/pr/10"); //false
```
IMHO - The method matches should have returned true as it is Ant style matching. Its interesting to see that there is a similar class with same name(AntPathMatcher) in Spring Core which does this correctly(and surprisingly, it was also wrong in the older versions). See - https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/util/AntPathMatcher.html
Please suggest how to get this right - resolving index.html with mapping mentioning path params.
You can simply do /pr/*
The notion of variables in this context doesn't make sense because we have no usage for those variables
/pr/* will not solve the issue. It will match a URL pattern /pr/1 and look up resources under folder 1(what’s returned by AntPathMatcher.html#extractPathWithinPattern). This is not our case. We still want to resolve index.html with variable 1.
The notion of variables in this context doesn't make sense because we have no usage for those variables
I don’t quite understand what is meant by that. Consider a case where the application loads pages for details of a specific pr by matching the pr Id in provided url. e.g. - /pr/123 will lead to the application which has to display the details of pr#123. In a React app we have to resolve parameter by path matching under Routes and query the server using the is 123.
I didn’t say that you have no usage for the variable. The variables have no
usage in the context of resolving a view.
On Wed, Feb 5, 2020 at 7:51 PM abksrv notifications@github.com wrote:
The notion of variables in this context doesn't make sense because we have
no usage for those variablesI don’t quite understand what is meant by that. Consider a case where the
application loads pages for details of a specific pr by matching the pr Id
in provided url. e.g. - /pr/123 will lead to the application which has to
display the details of pr#123. In a React app we have to resolve parameter
by path matching under Routes and query the server using the is 123.—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/micronaut-projects/micronaut-core/issues/2730?email_source=notifications&email_token=AAMCVLIC3URGUMQLA2MBIU3RBNNIFA5CNFSM4KQCBFQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEK5Q2TA#issuecomment-582683980,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAMCVLKY7YMXTSSA3C4A2SLRBNNIFANCNFSM4KQCBFQQ
.
@abksrv I understand what you're trying to do now. Unfortunately the static mapping is not for mapping generic URLs to resources. It's to allow for direct access to resources. You can register a route that renders the index page for this purpose.
Something like this should match routes that didn't match anything else and will then render the index page. Of course you can modify the url template there to your liking.
@Get("/{path:[^\\.]*}")
public Optional<StreamedFile> forward(String path) {
return environment.getResource("classpath:static/index.html")
.map(StreamedFile::new);
}