Skip to content

Commit da852be

Browse files
committed
Adds IgnoreBase param to static middleware docs
1 parent 98e1a32 commit da852be

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

website/content/middleware/static.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,20 @@ e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
3030
}))
3131
```
3232

33-
This serves static files from `static` directory and enables directory browsing.
33+
This serves static files from `static` directory and enables directory browsing.
34+
35+
Default behavior when using with non root URL paths is to append the URL path to the filesystem path.
36+
37+
Example:
38+
39+
```go
40+
group := root.Group("somepath")
41+
group.Use(middleware.Static(filepath.Join("filesystempath")))
42+
// When an incoming request comes for `/somepath` the actual filesystem request goes to `filesystempath/somepath` instead of only `filesystempath`.
43+
```
44+
45+
To turn off this behavior set the `IgnoreBase` config param to `true`.
46+
3447

3548
## Configuration
3649

@@ -55,6 +68,12 @@ StaticConfig struct {
5568
// Enable directory browsing.
5669
// Optional. Default value false.
5770
Browse bool `json:"browse"`
71+
72+
// Enable ignoring of the base of the URL path.
73+
// Example: when assigning a static middleware to a non root path group,
74+
// the filesystem path is not doubled
75+
// Optional. Default value false.
76+
IgnoreBase bool `yaml:"ignoreBase"`
5877
}
5978
```
6079

0 commit comments

Comments
 (0)