staticbackendhq / core

Backend server API handling user mgmt, database, storage and real-time component
https://staticbackend.com
MIT License
682 stars 67 forks source link

Embed UI templates via go:embed #65

Closed dstpierre closed 1 year ago

dstpierre commented 1 year ago

By implementing the backend package I discover that the //go:embed directive works when importing external package.

Since the CLI uses the core package to expose a fully working local dev server, it would be nice to embed the templates for the web admin UI.

That way they'd be available from the CLI.

We'd use them like this in the render.go file:

//go:embed templates
var templFS embed.FS

Once this is done, the loadTemplates in render.go line:20 should be changed to use the templFS above. Use the the io/fs instead of os to ReadDir.

Conor-Fleming commented 1 year ago

Hi @dstpierre. I can work on this issue, if that's ok. Seems pretty straightforward based on your description.

dstpierre commented 1 year ago

that's great @Conor-Fleming let me know if you have any questions

dstpierre commented 1 year ago

@Conor-Fleming it would be nice if this change also brings in the CSS and logo image in a "public" directory that would be embeded as well.

For example, at this moment in templates/login.html line 14 there's a that references the logo from https, same from templates/partials/navbar.html line:5.

And for the CSS it's in templates/login.html line:8 and templates/partials/head.html line:13.

Would be nice to create a public directory, embed it and serve it's content. This involved changing the URL to access those resources in the html file above.

See this go doc part for how to serve content from an embed.FS.

Let me know if you have any questions.

Conor-Fleming commented 1 year ago

Cool, I'll take a stab and let you know if I need anything. Thanks for the clear direction!

Conor-Fleming commented 1 year ago

I have created a public directory and added the logo-sb-no-txt.png & sb-app.css files as mentioned above. Would the best place to embed this new public directory and serve these files be in the existing server.go file? Or would you rather create a new file to do this? @dstpierre

Thanks in advance.

dstpierre commented 1 year ago

@Conor-Fleming yes server.go is a good file to have the embed.FS variable.

sorry for the delay.

dstpierre commented 1 year ago

@Conor-Fleming I'm doing a friendly follow-up here, I'm planning a new release and would want this issue to be available in the next CLI update.

Can you update on your status, are you still interested in tackling this one?

Please let me know, thanks.

Conor-Fleming commented 1 year ago

HI @dstpierre,

Apologies, I'm going to have to let this one go for the time being. Again so sorry.

dstpierre commented 1 year ago

@Conor-Fleming no worries at all, thanks for confirming.