huma icon indicating copy to clipboard operation
huma copied to clipboard

How to add a catch-all route and static asset handling to serve html + assets

Open MichaelBurgess opened this issue 3 years ago • 3 comments

As this is built on top of chi I feel/hope this should be possible, but I'm not seeing any APIs in huma to do this?

Forgive me if there's an obvious solution but I'm still getting to grips with this framework.

MichaelBurgess avatar Feb 24 '21 22:02 MichaelBurgess

if I could get to the chi router then perhaps I could do this? https://github.com/go-chi/chi/blob/master/_examples/fileserver/main.go

MichaelBurgess avatar Feb 24 '21 22:02 MichaelBurgess

My ideal setup is really this:

  • /api/<known set of API routes> - huma routes
  • /api/* - anything not defined above = 404
  • /assets/* - serve up CSS / JS / images etc
  • /* - any other request, serve index.html (which in turn will reference CSS / JS / etc assets)

Is this possible with huma? Looks like I'm only really needing this for the known API routes to get the Open API docs, but need to break out of the model for everything else?

MichaelBurgess avatar Feb 24 '21 23:02 MichaelBurgess

Also looking for this to bundle a simple SPA Admin page.

As I can see it - Best way to do this right now, is write our own New function to return a Router?

Fishwaldo avatar Jul 25 '22 04:07 Fishwaldo

With Huma v2 and the bring-your-own-router approach, this is now possible by just adding whatever route you need to the router itself, including using e.g. https://pkg.go.dev/net/http#FileServer

danielgtaylor avatar Oct 22 '23 03:10 danielgtaylor