Nginx to caddy convert (if + add_header + rewrite)

- explain what you are trying to do,

Caddy + CORS setup

- show what you have already tried,

caddyfile cors snippet:

cors / {
origin https://api.mydomain
origin http://localhost
allow_credentials true
max_age 1728000
allowed_headers Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,Access-Control-Allow-Headers,Access-Control-Allow-Origin
exposed_headers Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,Access-Control-Allow-Headers,Access-Control-Allow-Origin

- include error messages and log output,
for OPTIONS request, access-control-allow-origin has the right value but for POST request it has a duplicate value:
access-control-allow-origin = http://localhost, http://localhost
and I get the error message:

The ‘Access-Control-Allow-Origin’ header contains multiple values… but only one is allowed


Any idea about what’s going on here?


G’day @RAA, welcome to the Caddy community!

Strange that it works for OPTIONS but wigs out on a POST… Sounds like it could be buggy behaviour.

The CORS plugin is developed outside of the core Caddy project. You’ll probably want to open an issue on the repo, here: GitHub - captncraig/cors: Cross Origin Resource Sharing middleware for go

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.