micronaut-guides
micronaut-guides copied to clipboard
Native serving of SPAs
I think we could make serving SPAs simpler as it is common pattern to use Micronaut for API and bundle SPA frontend application as static resource.
My proposed solution is to extend StaticResourceConfiguration
class with something like
private boolean spa = false;
and extend StaticResourceResolver
class with something like
if (config.isSpa()) {
for (ResourceLoader loader : loaders) {
Optional<URL> resource = loader.getResource(INDEX_PAGE);
if (resource.isPresent()) {
return resource;
}
}
}
under the end of loop finding available resource (for (ResourceLoader loader : loaders)
) when no resource is found.
Usage in application.yml
would be:
micronaut:
router:
static-resources:
angular-frontend:
paths: classpath:public/frontend
mapping: /frontend/**
spa: true
- Would you like me to create PR?
- Is naming it
spa
good? Maybe something likefallback-to-index
?