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

Export endpoint constants #2788

Open
OlliTietavainenVaadin opened this issue Oct 3, 2024 · 1 comment
Open

Export endpoint constants #2788

OlliTietavainenVaadin opened this issue Oct 3, 2024 · 1 comment
Labels
enhancement New feature or request hilla Issues related to Hilla

Comments

@OlliTietavainenVaadin
Copy link
Member

Describe your motivation

Currently, generated endpoints contain a hard-coded paths to the service and the method to be called, as well as a constant Hilla-specific prefix.

Generated endpoints can't currently be called from service workers because of CSRF information needed from the document head (or a cookie), but once the CSRF token is supplied to the service workers, there's nothing preventing the service worker from calling the endpoint method. This just means that the fetch call needs to be built manually, which can be done based on the information found from the generated sources plus the CSRF token. This is prone to breaking if anything changes either in the endpoint methods or in Hilla internals.

Describe the solution you'd like

The simplest approach would be to alter the endpoint generation in a way that the generated modules export the constant values used in there: the service name, the method name, and the clientconnect prefix. This would make any custom code calling the endpoints more stable and changes in the generated artifacts or in Hilla internals would be less likely to break usage.

Describe alternatives you've considered

Most use cases won't need the exported constants, and the generated codebase will be slightly larger than without this feature, so it could be beneficial to make the exports configurable, e.g. with a special annotation like @ExportConstants, an annotation argument in @BrowserCallable like @BrowserCallable(exportConstants = true) or a configuration option in application.properties.

Additional context

No response

@platosha
Copy link
Contributor

That's an improvement, but let's focus on enabling endpoint calls from the service worker context instead. Using low-level fetch does not seem to be a good idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hilla Issues related to Hilla
Projects
None yet
Development

No branches or pull requests

2 participants