Hello everyone,
I'm running into a CORS issue with my setup using Ollama for LLM processing, a Zrok proxy, and Caddy as the server. I'm building a Flutter Web app and using the ollama_dart: ^0.2.0 package to make API calls.
Here is my Caddyfile
:
# Global config must be first
{
# No listen on 2019/tcp with admin API
admin off
debug
}
(cors) {
@cors_preflight method OPTIONS
@cors header Origin {args.0}
handle @cors_preflight {
header Access-Control-Allow-Origin "{args.0}"
header Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE"
header Access-Control-Allow-Headers "Content-Type"
header Access-Control-Max-Age "3600"
respond "" 204
}
handle @cors {
header Access-Control-Allow-Origin "{args.0}"
header Access-Control-Expose-Headers "Link"
}
}
# zrok site block
http:// {
bind {{ .ZrokBindAddress }}
import cors *
reverse_proxy 127.0.0.1:11434 {
header_up Host localhost:11434
}
}
However, I'm seeing this CORS error in the browser:
Access to fetch at 'https://myzroketoken.share.zrok.io/api/chat' from origin 'http://localhost:49793' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
The preflight request details are as follows:
- Request URL: https://myzroketoken.share.zrok.io/api/chat
- Request Method: OPTIONS
- Status Code: 200 OK
- Access-Control-Request-Headers: content-type,skip_zrok_interstitial
- Access-Control-Request-Method: POST
- Origin: http://localhost:49793
I've been trying to adjust the Caddyfile
configuration to handle CORS properly, but I keep hitting this issue. Any advice on resolving this? Am I missing something in my CORS setup with Caddy or Zrok?
Thanks in advance!