vaadin / vaadin-connect

A Vaadin Labs experiment with a secure stateless communication framework
https://vaadin.com/labs/vaadin-connect
Apache License 2.0
18 stars 5 forks source link

dynamically set the base URL in index.html returned by Vaadin Frontend Server #179

Open vlukashov opened 5 years ago

vlukashov commented 5 years ago

When serving a single page application with Vaadin Frontend Server I want it to dynamically set the <base href=""> tag in the response to compensate the level of nesting of the requested URL so that relative links like <a href="users/32"></a> would still work regardless of the URL used to load the SPA.

Example: In an SPA the same index.html file is returned for / and /users (and for all routes of the SPA) and the same page content is rendered from the view templates. If a view template contains a link like <a href="users/32">Sam's profile</a>, then when the SPA is loaded via / that link is resolved to /users/32. And when the SPA is loaded via /users, then the origin of the page is /users/, and that same link is resolved to /users/users/32. This complicates creating relative links in SPA view templates: simple relative links are not supported and one needs to use some helper function in the view templates to normalize relative URLs taking into account the page origin.

Browses can do that automatically if the page contains a <base href="..."> tag. In the above example the / request should return <base href="./">, and the /users request would should<base href="../"> in order for simple relative links to work without extra handling.

DoD:

vlukashov commented 5 years ago

add a boolean config option to the frontend server config: enable / disable the base URL rewrite. default: enable

platosha commented 5 years ago

As discussed f2f with the team: