Skip to content

Instantly share code, notes, and snippets.

@alexanderadam
Forked from blacksheep--/Dockerfile
Created March 11, 2020 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexanderadam/4e05f7a0382eb6b45fd3e4303d5c33f8 to your computer and use it in GitHub Desktop.
Save alexanderadam/4e05f7a0382eb6b45fd3e4303d5c33f8 to your computer and use it in GitHub Desktop.
Traefik Catch-All to return HTTP421 for unresolved routes
// 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)
}
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
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