Middleware to add the "/" if needed

I had some issues with the other recommended solutions here. My goal was to get the /dashboard path to redirect to /dashboard/ so that the traefik dashboard would be easier to get to.

Here is the solution I ended up with... Note, it isn't a catchall and it is hard coded for the /dashboard path, but it is a good starting point that should be easy to expand with wildcards.

      labels:
        - traefik.enable=true

        # required in swarm, but can be any port number. 
        - traefik.http.services.api@internal.loadbalancer.server.port=8080
        - traefik.http.routers.dashboard.rule=Host(`example.com`) && (PathPrefix(`/dashboard`) || PathPrefix(`/api`))
        
        # middlewares
        - traefik.http.middlewares.dashboard-auth.basicauth.users={{ htpasswd }}
        - traefik.http.routers.dashboard.middlewares=dashboard-auth
        
        # Add trailing slash to /dashboard path
        - traefik.http.middlewares.dashboard-strip-slash.redirectregex.regex=(^.*\/dashboard$$)
        - traefik.http.middlewares.dashboard-strip-slash.redirectregex.replacement=$$1/
        - traefik.http.middlewares.dashboard-strip-slash.redirectregex.permanent=false
        - traefik.http.routers.dashboard.middlewares=dashboard-strip-slash