-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Add StaticFS method #2059
Comments
(default)filesystem will be added in currently e.StaticFS can be emulated if you add route with no-op handler and static middleware with filesystem Line 48 in 4fffee2
something like that. Probably needs some e.GET("/files/*", echo.NotFoundHandler, middleware.StaticWithConfig(middleware.StaticConfig{
Filesystem: http.Dir("./"),
})) |
This is now implemented with #2064 and will be made available with echo v4.7 |
In Angular, you get all built files in one directory by default. Let's say I embed this directory as I am unsure how to do this even with #2064 or am I missing something? |
@clemensg this is what "static" middleware" can do. Please check Lines 27 to 34 in 4a1ccdf
|
@aldas Thank you! I missed the new Filesystem option in the Static Middleware (not in the docs yet), which makes it possible to use it with embed.FS 👍 |
Closing, this stuff is now released with |
In case anyone else needs this, here's a working example (tested with go v1.18): package main
import (
"embed"
"flag"
"fmt"
"net/http"
"github.com/labstack/echo/v4"
echoMw "github.com/labstack/echo/v4/middleware"
)
// If you have files starting with "_" that you want to serve, use "all:"
//go:embed all:public
var public embed.FS
func main() {
var port int
flag.IntVar(&port, "port", 8000, "The port to listen on")
flag.Parse()
e := echo.New()
e.Use(echoMw.StaticWithConfig(echoMw.StaticConfig{
Root: "public", // This is the path to your SPA build folder, the folder that is created from running "npm build"
Index: "index.html", // This is the default html page for your SPA
Browse: false,
HTML5: true,
Filesystem: http.FS(public),
}))
e.Logger.Fatal(e.Start(fmt.Sprintf(":%d", port)))
} |
Issue Description
Checklist
Expected behaviour
As of Echo 4.6.1, we have the
(*Echo).Static(prefix, root string) *Route
method. With the advent of Go 1.16, we have the new fs.FS type which expands upon the older concept of http.Dir as used by http.FileServer, to allow serving of files from any FS-like location, not just on disk.I think it would be logical for Echo to support this new standard as well. The simplest approach I think would be to add a
StaticFS
method, probably with the following signature:Version/commit
v4.6.1
The text was updated successfully, but these errors were encountered: