Skip to content

Webflux webjars path cannot be prefixed with a context root #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
davidmelia opened this issue Aug 7, 2019 · 2 comments
Closed

Webflux webjars path cannot be prefixed with a context root #24

davidmelia opened this issue Aug 7, 2019 · 2 comments
Labels
wontfix This will not be worked on

Comments

@davidmelia
Copy link

Regarding the demo springdoc-openapi-test-app3 (3.1.1-SNAPSHOT) if I set the following

springdoc:
  api-docs:
    path: /dave/v3/api-docs
  swagger-ui:
    path: /dave/swagger-ui.html     

then
http://localhost:8080/dave/swagger-ui.html
redirects to
http://localhost:8080/webjars/swagger-ui/index.html?url=/dave/v3/api-docs&validatorUrl=
but should be
http://localhost:8080/dave/webjars/swagger-ui/index.html?url=/dave/v3/api-docs&validatorUrl=

is this a bug or is it possible to have a parameter to prefix /webjars?

Thanks

@springdoc
Copy link
Collaborator

springdoc commented Aug 7, 2019

webjars are not only linked to webflux. They are used by swagger-ui.
The url of swagger-ui.html and API, are the same as the application.yml file. So there is no bug.
If you want to add a prefix to webjars url: You have to add your custom configuration of spring-mvc.
For example:

@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/dave/webjars/**").addResourceLocations("/webjars/").resourceChain(false);

	}

	@Override
	public void addViewControllers(ViewControllerRegistry registry) {
		registry.addRedirectViewController("/webjars/swagger-ui/index.html", "/dave/webjars/swagger-ui/index.html")
				.setKeepQueryParams(true);
	}

	@Bean
	public ViewResolver getViewResolver() {
		return new InternalResourceViewResolver();
	}
}

On webflux side, unlike Spring MVC at present in WebFlux there is no way to transparently rewrite static resource URLs since the are no view technologies that can make use of a non-blocking chain of resolvers and transformers (e.g. resources on Amazon S3). When serving only local resources the workaround is to use ResourceUrlProvider directly (e.g. through a custom tag) and block for 0 seconds.

@springdoc springdoc added the wontfix This will not be worked on label Aug 7, 2019
@msokolowski1991
Copy link

msokolowski1991 commented Feb 10, 2020

Set springdoc.webjars.prefix property to /dave/webjars
and then override ResourceHandlers of WebFluxConfigurer

    override fun addResourceHandlers(registry: ResourceHandlerRegistry) {
        registry
            .addResourceHandler("/dave/webjars/**")
            .addResourceLocations("classpath:/META-INF/resources/webjars/")
            .resourceChain(false)
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants