Skip to content
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

Welcome page support in Spring WebFlux #9785

Closed
bijukunjummen opened this issue Jul 18, 2017 · 11 comments
Closed

Welcome page support in Spring WebFlux #9785

bijukunjummen opened this issue Jul 18, 2017 · 11 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@bijukunjummen
Copy link
Contributor

For a webflux project(using 2.0.0.M2) the welcome page in classpath:/static/index.html is not getting resolved for root uri / and returns a 404 status.

However it is served out if I access /index.html explicitly.

@bijukunjummen bijukunjummen changed the title Welcome page(classpath:/static/index.html) not being resolved for / uri Welcome page(classpath:/static/index.html) not being resolved for / uri in webflux project Jul 18, 2017
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 18, 2017
@bclozel bclozel added theme: webflux type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 19, 2017
@mikaelhg
Copy link

mikaelhg commented Jul 25, 2017

A workaround:

import org.springframework.core.io.Resource
import org.springframework.http.MediaType.*
import org.springframework.web.reactive.function.server.ServerResponse.ok
import org.springframework.web.reactive.function.server.router

@Configuration
class ApplicationRoutes {

    @Value("classpath:/static/index.html")
    private lateinit var indexHtml: Resource

    @Bean
    fun mainRouter() = router {
        GET("/") {
            ok().contentType(TEXT_HTML).syncBody(indexHtml)
        }
    }
}

@imedvedko
Copy link

Hi!

Question on stackoverflow contains workaround: https://stackoverflow.com/questions/45147280/spring-webflux-how-to-forward-to-index-html-to-serve-static-content

@sivaprasadreddy
Copy link

Why not have addViewControllers(ViewControllerRegistry registry) method in WebFluxConfigurer similar to WebMvcConfigurer?

@wilkinsona
Copy link
Member

@sivaprasadreddy WebFluxConfigurer is part of Spring Framework.

@bclozel bclozel added this to the 2.1.x milestone Oct 15, 2018
@bclozel bclozel added the status: blocked An issue that's blocked on an external project change label Oct 16, 2018
@bclozel
Copy link
Member

bclozel commented Oct 16, 2018

Waiting for SPR-17389.

@philwebb philwebb modified the milestones: 2.1.x, 2.x Oct 24, 2018
@bclozel bclozel removed the status: blocked An issue that's blocked on an external project change label May 20, 2020
@bclozel bclozel modified the milestones: 2.x, 2.3.1 May 20, 2020
@bclozel bclozel self-assigned this May 22, 2020
@bclozel bclozel changed the title Welcome page(classpath:/static/index.html) not being resolved for / uri in webflux project Welcome page support in Spring WebFlux May 22, 2020
@jan-peremsky
Copy link

@bclozel
The commit 525e03d affects spring boot applications defining their own explicit welcome pages via explicit RouterFunction bean.
This is because the WelcomePageConfiguration has no @ConditionalOnXXX annotation so it effectively overrides/supersedes any welcome page configuration provided in the application because it is processed prior to the RouterFunction defined in the app.
And if the explicit welcome page is rendered from a template with an explicit model ServerResponse.ok().render("index", model) it is not rendered correctly.

@Order annotation has to be used on the explicit welcome page RouterFunction.

If this behavior is intentional, it should be at least documented. Otherwise it is a bug.

@bclozel
Copy link
Member

bclozel commented Jun 15, 2020

@jan-peremsky See #21909

bclozel added a commit that referenced this issue Jun 15, 2020
Prior to this commit, the welcome page support implemented in gh-9785
would override existing index views in both annotation and functional
variants.

This comes from the fact that the feature was implemented as a
`RouterFunction` configured in the main `RouterFunctionMapping` bean.
Due to ordering issues between mappings, this would override existing
application mappings in some cases.

This commit ensures that the welcome page `RouterFunction` is
contributed to the context in its own handler mapping, ordered after the
application ones.

Fixes gh-21909
@xJoeWoo
Copy link
Contributor

xJoeWoo commented Jul 5, 2020

@bclozel
The commit 525e03d affects spring boot applications defining their own explicit welcome pages via explicit RouterFunction bean.
This is because the WelcomePageConfiguration has no @ConditionalOnXXX annotation so it effectively overrides/supersedes any welcome page configuration provided in the application because it is processed prior to the RouterFunction defined in the app.
And if the explicit welcome page is rendered from a template with an explicit model ServerResponse.ok().render("index", model) it is not rendered correctly.

@Order annotation has to be used on the explicit welcome page RouterFunction.

If this behavior is intentional, it should be at least documented. Otherwise it is a bug.

Totally agreed!

RouterFunction bean method is marked @ConditionalOnMissingBean(RouterFunction::class) in my util library. It collects custom routers and transform them into Spring's RouterFunction.
Now all projects that depends on util library got 404 due to no routers were registered! @Order(0) was useless, @ConditionalOnMissingBean had to be removed for now.

Will next update fix the pollution of RouterFunction?

@bclozel
Copy link
Member

bclozel commented Jul 5, 2020

@xJoeWoo See #21909

@xJoeWoo
Copy link
Contributor

xJoeWoo commented Jul 5, 2020

@bclozel Thanks! Is there any clues about the release time of new version?

@bclozel
Copy link
Member

bclozel commented Jul 5, 2020

The scheduled release dates are available on GitHub. See https://github.com/spring-projects/spring-boot/milestone/173

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

10 participants