mirror of
https://github.com/halverneus/static-file-server.git
synced 2024-11-24 09:05:30 +00:00
Initial commit.
This commit is contained in:
commit
8548fe5772
8
Dockerfile
Normal file
8
Dockerfile
Normal file
@ -0,0 +1,8 @@
|
||||
FROM golang:latest as builder
|
||||
COPY serve.go /
|
||||
WORKDIR /
|
||||
RUN CGO_ENABLED=0 go build -a -installsuffix cgo -o serve .
|
||||
|
||||
FROM scratch
|
||||
COPY --from=builder /serve /
|
||||
CMD ["/serve"]
|
24
serve.go
Normal file
24
serve.go
Normal file
@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
host := env("HOST", "")
|
||||
port := env("PORT", "8080")
|
||||
folder := env("FOLDER", "/web") + "/"
|
||||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, folder+r.URL.Path)
|
||||
})
|
||||
http.ListenAndServe(host+":"+port, nil)
|
||||
}
|
||||
|
||||
func env(key, fallback string) string {
|
||||
if value := os.Getenv(key); 0 < len(value) {
|
||||
return value
|
||||
}
|
||||
return fallback
|
||||
}
|
Loading…
Reference in New Issue
Block a user