-
-
Save alexanderadam/4e05f7a0382eb6b45fd3e4303d5c33f8 to your computer and use it in GitHub Desktop.
Traefik Catch-All to return HTTP421 for unresolved routes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// inspired by https://github.com/mergermarket/404 | |
package main | |
import "net/http" | |
func healthcheck_handler(res http.ResponseWriter, req *http.Request) { | |
res.WriteHeader(http.StatusOK) | |
} | |
func default_handler(res http.ResponseWriter, req *http.Request) { | |
res.WriteHeader(http.StatusMisdirectedRequest) | |
} | |
func main() { | |
http.HandleFunc("/internal/healthcheck", healthcheck_handler) | |
http.HandleFunc("/", default_handler) | |
http.ListenAndServe(":80", nil) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "2.1" | |
services: | |
catchall: | |
restart: always | |
build: | |
context: . | |
networks: | |
- web | |
labels: | |
- "traefik.enable=true" | |
- "traefik.docker.network=web" | |
- "traefik.http.routers.catchall_router.entrypoints=web" | |
- "traefik.http.routers.catchall_router.rule=HostRegexp:(`{catchall:.*}`)" # <<--- | |
- "traefik.http.routers.catchall_router.priority=1" # <<--- | |
- "traefik.http.routers.catchall_router.service=catchall_service@docker" | |
- "traefik.http.routers.catchall_router_ssl.entrypoints=web-secure" | |
- "traefik.http.routers.catchall_router_ssl.rule=HostRegexp:(`{catchall:.*}`)" # <<--- | |
- "traefik.http.routers.catchall_router_ssl.priority=1" # <<--- | |
- "traefik.http.routers.catchall_router_ssl.tls=true" | |
- "traefik.http.routers.catchall_router_ssl.service=catchall_service@docker" | |
- "traefik.http.services.catchall_service.loadbalancer.server.port=80" | |
networks: | |
web: | |
external: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM golang:1.14-alpine | |
COPY . /go/src/app | |
WORKDIR /go/src/app | |
RUN go get -v -d | |
RUN go install | |
CMD ["app"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment