Remote Embedding fails with CORS error when using local Ollama
Environment
- ReadAny version: v1.3.3
- OS: Windows 11
- Ollama version: 0.30.7
Problem Description
When configuring a Remote Embedding model pointing to a local Ollama instance, ReadAny reports "failed to fetch". The root cause is a CORS policy violation: ReadAny runs under the origin http://tauri.localhost, which Ollama does not allow by default.
Root Cause Analysis
Opening DevTools (via environment variable) revealed the actual error:
Access to fetch at 'http://localhost:11434/v1/embeddings' from origin
'http://tauri.localhost' has been blocked by CORS policy:
Response to preflight request doesn't pass access control check.
Ollama rejects the preflight OPTIONS request from http://tauri.localhost.
Even after setting OLLAMA_ORIGINS=*, a duplicate Access-Control-Allow-Origin header issue appeared (*, http://localhost:11434), which also caused the request to fail.
Workaround: Caddy Reverse Proxy
The following Caddy configuration resolves all three issues:
- Handles
OPTIONS preflight requests correctly
- Rewrites the
Origin header before forwarding to Ollama
- Removes Ollama's own
Access-Control-Allow-Origin header to prevent duplicates
Caddyfile:
{
auto_https off
}
:11435 {
@options method OPTIONS
handle @options {
header Access-Control-Allow-Origin "*"
header Access-Control-Allow-Headers "*"
header Access-Control-Allow-Methods "*"
respond 204
}
reverse_proxy 127.0.0.1:11434 {
header_up Origin "http://localhost:11435"
header_up Host "localhost:11434"
header_down -Access-Control-Allow-Origin
}
header Access-Control-Allow-Origin "*"
header Access-Control-Allow-Headers "*"
header Access-Control-Allow-Methods "*"
}
Then configure ReadAny with:
- API Endpoint:
http://localhost:11435/v1/embeddings
- Model ID:
bge-m3
- API Key:
ollama (any value)
Suggestion
It would be great if ReadAny could handle this more gracefully, either by:
- Adding
OLLAMA_ORIGINS setup instructions to the documentation for local Ollama users
- Using Tauri's native HTTP client (
@tauri-apps/plugin-http) instead of browser fetch for embedding requests — this would bypass WebView2 CORS restrictions entirely and allow direct access to local services without a reverse proxy
Steps Others Can Follow to Reproduce
- Install Ollama, pull any embedding model (e.g.
ollama pull bge-m3)
- In ReadAny v1.3.3, go to Settings → Vector Model → Remote Models → Add Model
- Set APIendpoint to
http://localhost:11434/v1/embeddings, model ID bge-m3
- Click Save, and then click the Test button → "failed to fetch"
- Open DevTools to see the actual CORS error
Remote Embedding fails with CORS error when using local Ollama
Environment
Problem Description
When configuring a Remote Embedding model pointing to a local Ollama instance, ReadAny reports "failed to fetch". The root cause is a CORS policy violation: ReadAny runs under the origin
http://tauri.localhost, which Ollama does not allow by default.Root Cause Analysis
Opening DevTools (via environment variable) revealed the actual error:
Ollama rejects the preflight
OPTIONSrequest fromhttp://tauri.localhost.Even after setting
OLLAMA_ORIGINS=*, a duplicateAccess-Control-Allow-Originheader issue appeared (*, http://localhost:11434), which also caused the request to fail.Workaround: Caddy Reverse Proxy
The following Caddy configuration resolves all three issues:
OPTIONSpreflight requests correctlyOriginheader before forwarding to OllamaAccess-Control-Allow-Originheader to prevent duplicatesCaddyfile:
Then configure ReadAny with:
http://localhost:11435/v1/embeddingsbge-m3ollama(any value)Suggestion
It would be great if ReadAny could handle this more gracefully, either by:
OLLAMA_ORIGINSsetup instructions to the documentation for local Ollama users@tauri-apps/plugin-http) instead of browserfetchfor embedding requests — this would bypass WebView2 CORS restrictions entirely and allow direct access to local services without a reverse proxySteps Others Can Follow to Reproduce
ollama pull bge-m3)http://localhost:11434/v1/embeddings, model IDbge-m3