3

I have the following configuration for serving static content from Spring Boot.

    @Configuration
    public class WebConfig implements WebMvcConfigurer {

        @Value("${frontend.location}")
        private String frontendLocation;

        @Override
        public void addViewControllers(ViewControllerRegistry reg) {
            reg.addViewController("/").setViewName("forward:/index.html");
            reg.addViewController("/{x:[\\w\\-]+}").setViewName("forward:/index.html");
        }

        @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
            registry.addResourceHandler("/**").addResourceLocations(frontendLocation);
        }

    }

This works fine as long as there is no server.servlet.context-path. When server.servlet.context-path is configured, it is being passed down to the frontend router as part of the URL. enter image description here The solution would be not to forward context path to index.html. How can I achieve that?

kswr
  • 57
  • 8

0 Answers0