GET / => index.html

This commit is contained in:
Neale Pickett 2023-03-04 13:27:15 -07:00
parent 0c94a7da09
commit 9889ed7917
5 changed files with 33 additions and 13 deletions

View File

@ -1,15 +1,17 @@
FROM golang:1 AS build
FROM golang:1-alpine AS build
WORKDIR /src
COPY go.* ./
RUN go mod download -x
COPY pkg ./pkg/
COPY cmd ./cmd/
RUN go get ./...
RUN CGO_ENABLED=0 GOOS=linux go install ./...
FROM alpine AS runtime
WORKDIR /target
COPY web web
COPY --from=build /go/bin/ .
FROM scratch
COPY --from=runtime /target /
WORKDIR /web
ENTRYPOINT ["/webfs"]

View File

@ -5,14 +5,31 @@ import (
"golang.org/x/net/webdav"
"log"
"net/http"
"strings"
)
type Handler struct {
webdav.Handler
}
func (h *Handler)ServeHTTP(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "GET", "HEAD":
if strings.HasSuffix(r.URL.Path, "/") {
r.URL.Path += "index.html"
}
}
h.Handler.ServeHTTP(w, r)
}
func main() {
address := flag.String("a", "localhost:8080", "Address to listen to.")
address := flag.String("a", ":8080", "Address to listen to")
directory := flag.String("d", ".", "Directory to serve")
flag.Parse()
handler := &webdav.Handler{}
handler.FileSystem = webdav.Dir(".")
handler := &Handler{}
handler.FileSystem = webdav.Dir(*directory)
handler.LockSystem = webdav.NewMemLS()
log.Println("Listening on", *address)

5
go.mod
View File

@ -2,7 +2,4 @@ module woozle.org/neale/webfs
go 1.15
require (
github.com/bakape/thumbnailer v1.0.0
golang.org/x/net v0.6.0
)
require golang.org/x/net v0.7.0

6
go.sum
View File

@ -1,5 +1,3 @@
github.com/bakape/thumbnailer v1.0.0 h1:fmaLCJ6sJ5wCAUmB3hhzgFAZ5G3cpueo3olI9N0ox3E=
github.com/bakape/thumbnailer v1.0.0/go.mod h1:PVB2nXXJHD4KAUWn9HaNKtWeDeAb9BFQ7oDOAdZCKUM=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
@ -7,8 +5,8 @@ golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0 h1:L4ZwwTvKW9gr0ZMS1yrHD9GZhIuVjOBBnaKH+SPQK0Q=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=

6
web/index.html Normal file
View File

@ -0,0 +1,6 @@
<!DOCTYPE html>
<html>
<title>webfs success</title>
<h1>It Worked!</h1>
<p>It's running. Now you need to mount something in <tt>/web</tt></p>
</html>