Skip to content

Commit 583680b

Browse files
committed
Add notes about leading slash in file related methods
1 parent a033b2c commit 583680b

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

website/docs/guide/static-files.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,20 @@ slug: /static-files
44
sidebar_position: 11
55
---
66

7-
# Static Files
7+
# Serving Static Files
88

99
Images, JavaScript, CSS, PDF, Fonts and so on...
1010

11+
## Default file system
12+
13+
Echo uses `os.DirFS(".")` as default a file system which is set to current working directory.
14+
To change the default file system, use `Echo#Filesystem` field.
15+
16+
```go
17+
e := echo.New()
18+
e.Filesystem = os.DirFS("assets")
19+
```
20+
1121
## Using Static Middleware
1222

1323
[See ](/middleware/static.md)
@@ -73,8 +83,16 @@ e.File("/", "public/index.html")
7383

7484
*Usage 2*
7585

76-
Serving a favicon from `images/favicon.ico`
86+
:::important
87+
88+
Leading `/` in the file path is will not work with most of the fs.FS implementations.
89+
90+
:::
91+
92+
Serving a favicon from `/app/assets/favicon.ico`
7793

7894
```go
79-
e.File("/favicon.ico", "images/favicon.ico")
95+
e := echo.New()
96+
e.Filesystem = os.DirFS("/")
97+
e.File("/favicon.ico", "app/assets/favicon.ico") // <--- file path must not have a leading slash
8098
```

0 commit comments

Comments
 (0)