Proxy endpoint show no cors error when cors are not provided

1. Caddy version (caddy version): 2.4.5

2. How I run Caddy:

a. System environment:

Windows 10: OS Build 19042.1237

b. Command:

caddy run --watch
ngrok http 8888

c. Service/unit/compose file:

N/A

d. My complete Caddyfile or JSON config:

:8888 { 
    handle / { 
        @200 { 
            expression {http.error.status_code} == 200
        }
        rewrite @200 /index.html
        file_server
    }

    handle /api/v1/ { 
        reverse_proxy localhost:3000 
        header { 
            Access-Control-Allow-Origin "*"
            Access-Control-Allow-Methods "GET"
        } 
    }

    handle /api/v2/ { 
        reverse_proxy localhost:3001
    }
    
    file_server {
        hide index.html
        hide 404.html
    }

    handle_errors {
        @404 {
            expression {http.error.status_code} == 404
        }
        rewrite @404 /404.html
        file_server
    }
}

3. The problem I’m having:

When going to my proxy endpoint /api/v2/ there is no cors error when I didn’t provide any cors header directive. How do I show cors error if I dont put any cors headers directive?

4. Error messages and/or full log output:

N/A

5. What I already tried:

Didnt provide any header directive of Access-Control-Allow-Origin "*"

6. Links to relevant resources:

N/A

I think you mean 2.4.5 :joy:

I don’t understand the question. CORS issues are not really a webserver issue, they’re more of a browser issue.

Are you sure you only want to handle requests to exactly / and not /foo and /bar for example? Path matching is exact in Caddy.

1 Like

Ohh my bad i was not in my head at the time and it was already late :joy: I was experimenting with caddy actually there are no production involve so I dont really mind about the path matching. Related to cors, im trying to set the cors headers on one of my proxy endpoint then i want to see if one or another get any cors related issues as I set it on the web server level and not on the endpoint services level if you get what I mean. I wasnt sure myself when I want to ask this question, hope someone can clarify it for me :sweat_smile: