log:
    level: INFO

entryPoints:
    web:
        # http
        address: ":80"

    web-secure:
        # https
        address: ":443"

certificatesResolvers:
    letsencrypt:
        # https://docs.traefik.io/master/https/acme/#lets-encrypt
        acme:
            email: "aztest07@azteam.vn"
            storage: /etc/traefik/acme/acme.json
            # https://docs.traefik.io/master/https/acme/#httpchallenge
            httpChallenge:
                entryPoint: web

http:
    routers:
        web-router:
            rule: "Host(`smartfarm.aztrace.vn`)"

            entryPoints:
                - web
            middlewares:
                - redirect
#                - csrf
#                - ui
            service: smart-farm-web-ui

        web-secure-router:
            rule: "Host(`smartfarm.aztrace.vn`)"

            entryPoints:
                - web-secure
#            middlewares:
#                - csrf
#                - ui
            service: smart-farm-web-ui
            tls:
                # https://docs.traefik.io/master/routing/routers/#certresolver
                certResolver: letsencrypt

        cdn-router:
            rule: "Method(`OPTIONS`, `GET`, `POST`, `DELETE`, `PUT`) && Host(`smartfarm.aztrace.vn`) && PathPrefix(`/upload`)"

            entryPoints:
                - web
            middlewares:
                - redirect
#                - csrf
#                - cdn
            service: smart-farm-cdn

        cdn-secure-router:
            rule: "Method(`OPTIONS`, `GET`, `POST`, `DELETE`, `PUT`) && Host(`smartfarm.aztrace.vn`) && PathPrefix(`/upload`)"

            entryPoints:
                - web-secure
#            middlewares:
#                - csrf
#                - cdn
            service: smart-farm-cdn
            tls:
                # https://docs.traefik.io/master/routing/routers/#certresolver
                certResolver: letsencrypt

        api-router:
            rule: "Method(`OPTIONS`, `GET`, `POST`, `DELETE`, `PUT`) && Host(`smartfarm.aztrace.vn`) && PathPrefix(`/api`)"

            entryPoints:
                - web
            middlewares:
                - redirect
                - cros
                # - crosHeader
            service: smart-farm-api

        api-secure-router:
            rule: "Method(`OPTIONS`, `GET`, `POST`, `DELETE`, `PUT`) && Host(`smartfarm.aztrace.vn`) && PathPrefix(`/api`)"

            entryPoints:
                - web-secure
            middlewares:
                - cros
                # - crosHeader
            service: smart-farm-api
            tls:
                # https://docs.traefik.io/master/routing/routers/#certresolver
                certResolver: letsencrypt

    middlewares:
        redirect:
            # https://docs.traefik.io/master/middlewares/redirectscheme/
            redirectScheme:
                scheme: https
                permanent: true
        csrf:
            # https://docs.traefik.io/master/middlewares/headers/#hostsproxyheaders
            # https://docs.djangoproject.com/en/dev/ref/csrf/#ajax
            headers:
                hostsProxyHeaders: [ "X-CSRFToken" ]
        cros:
            headers:
                # accessControlAllowCredentials: true
                accessControlAllowHeaders:
                    - access-control-allow-methods
                    - access-control-allow-origin
                    - cus_id
                    - token_key
                    - tmp
                accessControlAllowMethods:
                    - GET
                    - OPTIONS
                    - PUT
                    - POST
                    - DELETE
                accessControlAllowOriginList:
                    - http://localhost:4200
                    - http://ots.aztrace.vn
                    - http://smartfarm.aztrace.vn
                    - https://ots.aztrace.vn
                    - https://smartfarm.aztrace.vn
                # customRequestHeaders:
                #     X-Script-Name: "cus_id"
                #     X-Script-Name: "token_key"
                #     X-Script-Name: "tmp"
                # customResponseHeaders:
                #     X-Script-Name: "cus_id"
                #     X-Script-Name: "token_key"
                #     X-Script-Name: "tmp"
                accessControlMaxAge: 100
                addVaryHeader: true
                
        # crosHeader:
        #     headers:
        #         customRequestHeaders:
        #             X-Script-Name: "cus_id"
        #             X-Script-Name: "token_key"
        #             X-Script-Name: "tmp"
        #         customResponseHeaders:
        #             X-Script-Name: "cus_id"
        #             X-Script-Name: "token_key"
        #             X-Script-Name: "tmp"
#        ui:
#            addPrefix:
#                prefix: "/"
#            stripprefix:
#                prefixes: "/"
#        api:
#            addPrefix:
#                prefix: "/api"
#            stripprefix:
#                prefixes: "/api"
#        cdn:
#            addPrefix:
#                prefix: "/images"
#            stripprefix:
#                prefixes: "/images"
    services:
        smart-farm-web-ui:
            loadBalancer:
                servers:
                    -   url: http://smart-farm-web-ui

        smart-farm-api:
            loadBalancer:
                servers:
                    -   url: http://smart-farm-api:8080

        smart-farm-cdn:
            loadBalancer:
                servers:
                    -   url: http://smart-farm-cdn:90

providers:
    # https://docs.traefik.io/master/providers/file/
    file:
        filename: /etc/traefik/traefik.yml
        watch: true
