Serving a static dir, but with a custom handler for missed files? #2580
Replies: 1 comment
-
Probably not. Most of the middleware code deals with options that you probably do not need/is not related to your requirements. So rolling your own stupidly simple implementation (in a good way) is not wrong way to go. Have you looked into Static middleware? https://echo.labstack.com/docs/middleware/static#example-2 You index seems to be static (based on envs which do not change during runtime) so you could use static middleware with p.s. You could probably create own struct that implements filesystem interface and when static middleware tries to open index page it renders it from template and other files are read from actual (os)filesystem. |
Beta Was this translation helpful? Give feedback.
-
I would like to use echoserver to serve up an SPA with frontend routing. This means the root public dir should be served with e.Static, and that any 404 URLs must be instead sent to my custom index.html handler (uses templating to inject runtime environment variables). What is the idiomatic way to do this? I have a solution that involves filepath.Walk and to create routes.
Currently my entire code is:
Which seems to work, but wondering if there's an easier way than re-implementing e.Static.
Beta Was this translation helpful? Give feedback.
All reactions