Is it possible to host a static site alongside my Vaadin site in the same Servlet container?

I have a Vaadin website built out. The site has a landing page, plus an account section that a user can access when they login, and a checkout section where they pay to signup for service.

Is it possible to host the landing page (uri = /) as a static site within my Vaadin website? That is, within the same Spring Boot application.

Back story, the client hired an online marketing company to redesign that landing page and put all the SEO/goole-tracking stuff in it. The company re-implemented the landing page as a static page (static assets)… specifically an index.html and an assets directory full of images, css, and js. Now I am tasked with figuring out how to best host the static site, while still also supporting the checkout, login, and account pages.

Ideally I would like to host the static page within the same Spring Boot application that is hosting the Vaadin application. But I do not know if that is possible, hence this post

What I have tried so far. So far I removed the @Route("") route to see if I could then serve up the index.html for my new static landing page. But, at least in non-production mode, Vaadin still processes requests to / and gives this error… Could not navigate to ''. Exception = Couldn't find route for ''. So before I proceed further down this rabbit hole, I want to get a some advice. Is is possible to host a static site, specifically at /(root), alongside a fully functional Vaadin site in the same Spring Boot application?

Personal opinion which worked good for me:

  • place the static page in a Reverse Proxy like Apache Httpd or Nginx and change all URLs of your application to start with something like /app
  • configure the reverse proxy to serve anything from /app to your application

I see, so nginx would remove the /app before sending it to the application?

What about the JSESSION ID? If the user logs in, then goes to the landing page, then back to the /app/account, the JSESSION cookie might be gone (maybe) and they would have to log in again?

It depends how you have configured the cookie (domain vs sub path) and how long you store the session information if the user moves away from the app

You can configure nginx to remove the /app or configure your app to be served on the path (context path or servlet path depending on the technology)

Huge plus: serving a static page from a Reverse Proxy is really cheap / can easily be cached if somebody wants to DDos you. Having the “huge” java based application on a sub path or sub domain helps in that regard as well

Thank you so much for your valuable feedback. I will give this a shot.