http.internal can be used to protect resources. Authentication is handled by a backend. For this example it's written in Go.
git clone
this repo
Note: This is not meant to be used in a production environment. For production activate at least automatic HTTPS.
- download Caddy: https://caddyserver.com/download/darwin/amd64?license=personal&telemetry=off
- unpack and move binary into PATH
$ cd ./web/
$ caddy
- make sure go is installed
$ cd ./cmd/authenticaton/
$ go run main.go
unauthenticated:
- http://localhost:8080/internal → 404 Not Found
- http://localhost:8080/private/main.html → 404 Not Found
authenticated:
- http://localhost:8080/internal → 404 Not Found
- http://localhost:8080/private/main.html → 200 OK
- do not use index files in internal dir
- Given there is the file
internal/index.html
and the URL is/private/index.html
then the response will be a redirect to/internal/
. - see issue File server redirects not handled by internal middleware
- Given there is the file