:8080 {
    # Route based on Host header (set by haloy)
    @ask {
        host ask.xn--2dk.xyz
    }
    @db {
        host db.xn--2dk.xyz
    }

    handle @ask {
        handle /health {
            respond 200
        }

        handle /login {
            reverse_proxy 127.0.0.1:8081
        }

        handle /query {
            header Access-Control-Allow-Origin *
            header Access-Control-Allow-Methods "GET, POST, OPTIONS"
            header Access-Control-Allow-Headers "X-Password, Content-Type"

            @options method OPTIONS
            handle @options {
                respond 204
            }

            reverse_proxy 127.0.0.1:8081
        }

        @websocket {
            header Connection *Upgrade*
            header Upgrade websocket
        }

        handle @websocket {
            reverse_proxy localhost:7682 {
                flush_interval -1
            }
        }

        handle {
            forward_auth 127.0.0.1:8081 {
                uri /auth
                copy_headers Cookie
            }
            reverse_proxy localhost:7682 {
                flush_interval -1
            }
        }
    }

    handle @db {
        handle /health {
            respond 200
        }

        handle /login {
            reverse_proxy 127.0.0.1:8081
        }

        handle /query {
            header Access-Control-Allow-Origin *
            header Access-Control-Allow-Methods "GET, POST, OPTIONS"
            header Access-Control-Allow-Headers "X-Password, Content-Type"

            @options method OPTIONS
            handle @options {
                respond 204
            }

            reverse_proxy 127.0.0.1:8081
        }

        @websocket {
            header Connection *Upgrade*
            header Upgrade websocket
        }

        handle @websocket {
            reverse_proxy localhost:7681 {
                flush_interval -1
            }
        }

        handle {
            forward_auth 127.0.0.1:8081 {
                uri /auth
                copy_headers Cookie
            }
            reverse_proxy localhost:7681 {
                flush_interval -1
            }
        }
    }
}
