examples icon indicating copy to clipboard operation
examples copied to clipboard

Add an example for serving static assets with Encore

Open Minivera opened this issue 2 years ago • 2 comments

As part of writing a guide for using Encore as a server for serving web applications with injected data from the backend, I've prepared a small example that would probably work well in this repository. I'm also not 100% sure if this is the right approach for this kind of application, so this PR is probably a good way of valdiating that before I push a PR for the guide.

Minivera avatar Oct 08 '22 21:10 Minivera

In general, this feels quite hairy for being able to serve static assets. And it isn't the code itself; it is how Encore today isn't really built for embedding frontends. We do however want to make it easier for people to be able to write frontends within their Encore apps.

I would love to get input from those who have had previous thought about this such as @eandre and @DomBlack when they have a chance to contribute to the discussion :)

bih avatar Oct 10 '22 14:10 bih

We do however want to make it easier for people to be able to write frontends within their Encore apps.

Looking back at this example, I think the fact it delivers a fully-fledged react application might have not been the best choice for this example. I think where this can shine with Encore in its current state is in micro-frontends applications, especially if it delivers go templated HTML with web components. For example, consider this use case:

/app in the main service is an endpoint that uses authentication, if the user isn't authenticated, it serves a HTML file with a login page. If the user is authenticated, it serves the HTML and the JavaScript, which includes a few web components and iframes pointing to other encore systems/services.

Then each service also has a /app or similar endpoint that serves data with auth baked in and based on the GET params of the iframe or fetch params of the web components. They each care about deliver an HTML representation of their data and the app can be made super modular.

It can be weird to have systems deliver their own little piece of HTML, but it reduces the amount of back and forth between JavaScript and the backend (Including a lot less potentially buggy glue code) a lot and makes some standard use cases like login and auth a lot simpler (Consider the more standard CDN server dashboard where the user has to wait for the auth handshake to happen before they either see the login page or the logged in app).

Maybe this specific use case would be better represented in this example rather than serving a React app? I wanted to make it simpler, but I don't think it shines a light on what makes Encore for frontend potentially game-changing.

Minivera avatar Oct 10 '22 21:10 Minivera

Closing this as it is now quite stale. Sorry @Minivera that we didn't manage to work with you on adding this originally. Do hope you make further examples contributions and we will help get them swiftly merged!

marcuskohlberg avatar Sep 10 '24 13:09 marcuskohlberg