Skip to content

Commit 385cfba

Browse files
committed
feat: readd caddy to this repo
1 parent 05cca04 commit 385cfba

File tree

4 files changed

+451
-0
lines changed

4 files changed

+451
-0
lines changed

caddy/filemanager/filemanager.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package filemanager
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/filebrowser/filebrowser"
7+
"github.com/filebrowser/filebrowser/caddy/parser"
8+
h "github.com/filebrowser/filebrowser/http"
9+
"github.com/mholt/caddy"
10+
"github.com/mholt/caddy/caddyhttp/httpserver"
11+
)
12+
13+
func init() {
14+
caddy.RegisterPlugin("filemanager", caddy.Plugin{
15+
ServerType: "http",
16+
Action: setup,
17+
})
18+
}
19+
20+
type plugin struct {
21+
Next httpserver.Handler
22+
Configs []*filebrowser.FileBrowser
23+
}
24+
25+
// ServeHTTP determines if the request is for this plugin, and if all prerequisites are met.
26+
func (f plugin) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
27+
for i := range f.Configs {
28+
// Checks if this Path should be handled by File Manager.
29+
if !httpserver.Path(r.URL.Path).Matches(f.Configs[i].BaseURL) {
30+
continue
31+
}
32+
33+
h.Handler(f.Configs[i]).ServeHTTP(w, r)
34+
return 0, nil
35+
}
36+
37+
return f.Next.ServeHTTP(w, r)
38+
}
39+
40+
// setup configures a new FileManager middleware instance.
41+
func setup(c *caddy.Controller) error {
42+
configs, err := parser.Parse(c, "")
43+
if err != nil {
44+
return err
45+
}
46+
47+
httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handler) httpserver.Handler {
48+
return plugin{Configs: configs, Next: next}
49+
})
50+
51+
return nil
52+
}

caddy/hugo/hugo.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package hugo
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/filebrowser/filebrowser"
7+
"github.com/filebrowser/filebrowser/caddy/parser"
8+
h "github.com/filebrowser/filebrowser/http"
9+
"github.com/mholt/caddy"
10+
"github.com/mholt/caddy/caddyhttp/httpserver"
11+
)
12+
13+
func init() {
14+
caddy.RegisterPlugin("hugo", caddy.Plugin{
15+
ServerType: "http",
16+
Action: setup,
17+
})
18+
}
19+
20+
type plugin struct {
21+
Next httpserver.Handler
22+
Configs []*filebrowser.FileBrowser
23+
}
24+
25+
// ServeHTTP determines if the request is for this plugin, and if all prerequisites are met.
26+
func (f plugin) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
27+
for i := range f.Configs {
28+
// Checks if this Path should be handled by File Manager.
29+
if !httpserver.Path(r.URL.Path).Matches(f.Configs[i].BaseURL) {
30+
continue
31+
}
32+
33+
h.Handler(f.Configs[i]).ServeHTTP(w, r)
34+
return 0, nil
35+
}
36+
37+
return f.Next.ServeHTTP(w, r)
38+
}
39+
40+
// setup configures a new FileManager middleware instance.
41+
func setup(c *caddy.Controller) error {
42+
configs, err := parser.Parse(c, "hugo")
43+
if err != nil {
44+
return err
45+
}
46+
47+
httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handler) httpserver.Handler {
48+
return plugin{Configs: configs, Next: next}
49+
})
50+
51+
return nil
52+
}

caddy/jekyll/jekyll.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package jekyll
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/filebrowser/filebrowser"
7+
"github.com/filebrowser/filebrowser/caddy/parser"
8+
h "github.com/filebrowser/filebrowser/http"
9+
"github.com/mholt/caddy"
10+
"github.com/mholt/caddy/caddyhttp/httpserver"
11+
)
12+
13+
func init() {
14+
caddy.RegisterPlugin("jekyll", caddy.Plugin{
15+
ServerType: "http",
16+
Action: setup,
17+
})
18+
}
19+
20+
type plugin struct {
21+
Next httpserver.Handler
22+
Configs []*filebrowser.FileBrowser
23+
}
24+
25+
// ServeHTTP determines if the request is for this plugin, and if all prerequisites are met.
26+
func (f plugin) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
27+
for i := range f.Configs {
28+
// Checks if this Path should be handled by File Manager.
29+
if !httpserver.Path(r.URL.Path).Matches(f.Configs[i].BaseURL) {
30+
continue
31+
}
32+
33+
h.Handler(f.Configs[i]).ServeHTTP(w, r)
34+
return 0, nil
35+
}
36+
37+
return f.Next.ServeHTTP(w, r)
38+
}
39+
40+
// setup configures a new FileManager middleware instance.
41+
func setup(c *caddy.Controller) error {
42+
configs, err := parser.Parse(c, "jekyll")
43+
if err != nil {
44+
return err
45+
}
46+
47+
httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handler) httpserver.Handler {
48+
return plugin{Configs: configs, Next: next}
49+
})
50+
51+
return nil
52+
}

0 commit comments

Comments
 (0)