Skip to content

Bug: Remote Embedding fails with CORS error when using local Ollama #398

Description

@Agreeable3817

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:

  1. Handles OPTIONS preflight requests correctly
  2. Rewrites the Origin header before forwarding to Ollama
  3. 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:

  1. Adding OLLAMA_ORIGINS setup instructions to the documentation for local Ollama users
  2. 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

  1. Install Ollama, pull any embedding model (e.g. ollama pull bge-m3)
  2. In ReadAny v1.3.3, go to Settings → Vector Model → Remote Models → Add Model
  3. Set APIendpoint to http://localhost:11434/v1/embeddings, model ID bge-m3
  4. Click Save, and then click the Test button → "failed to fetch"
  5. Open DevTools to see the actual CORS error

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:aiAI, model configuration, vectorization, citations, promptsarea:desktopDesktop, Tauri, Windows, macOS, LinuxbugSomething isn't workingpriority:p1High: important feature broken or major platform/workflow regression

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions