Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] CORS issue #970

Open
12 tasks
huachuman opened this issue Nov 10, 2024 · 8 comments
Open
12 tasks

[FIX] CORS issue #970

huachuman opened this issue Nov 10, 2024 · 8 comments
Labels
fix Fix something that isn't working as expected

Comments

@huachuman
Copy link

huachuman commented Nov 10, 2024

Describe the bug

Access to fetch at 'https://app.khoj.dev/api/content?client=obsidian' from origin 'app://obsidian.md' has been blocked by CORS policy: 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.
app.khoj.dev/api/content?client=obsidian:1

  Failed to load resource: net::ERR_FAILED

plugin:khoj:1437

 Uncaught (in promise) TypeError: Failed to fetch

at updateContentIndex (plugin:khoj:1091:28)
at async eval (plugin:khoj:1432:39)

To Reproduce

do a manual sync

Screenshots

image

Platform

  • Server:
    • Cloud-Hosted (https://app.khoj.dev)
    • Self-Hosted Docker
    • Self-Hosted Python package
    • Self-Hosted source code
    • [ x ] Not sure. I also have the khoj app but gave up on it because it doesn't seem to work well. but this bug is about obsidian, not the app version.
  • Client:
    • [ x ] Obsidian
    • Emacs
    • Desktop app
    • Web browser
    • WhatsApp
  • OS:
    • [ x ] Windows
    • macOS
    • Linux
    • Android
    • iOS

If self-hosted

  • Server Version [e.g. 1.0.1]:

Additional context

Add any other context about the problem here.

@huachuman huachuman added the fix Fix something that isn't working as expected label Nov 10, 2024
@sabaimran
Copy link
Member

Hi @huachuman , where did you see the errors? Are they in the developer console, did you get a notification, or somewhere else? Can you also make sure you're on the latest obsidian plugin? To upgrade:

1. Open Community plugins tab in Obsidian settings
2. Click the Check for updates button
3. Click the Update button next to Khoj, if available

I'm not able to reproduce the error, so trying to understand how you might be encountering it.

Can you check in https://app.khoj.dev/settings > Files > Manage whether you have any data indexed?

@huachuman
Copy link
Author

huachuman commented Nov 11, 2024

So that error I get in the Obsidian console.

I can confirm that I'm on the latest version of the plugin (updated 9 days ago)

The only things I see in the files on https://app.khoj.dev/settings is a single PDF I uploaded a while ago for testing. I don't see anything in my obsidian vault there. I have also confirmed that the API key matches the one I have in Obsidian.

Could it have something to do with this?
image

@debanjum
Copy link
Member

So I was looking into this issue again. But I still can't reproduce the CORS issue you are facing. It'd be great if you can share the following details to investigate/reproduce the CORS issue you are facing:

  • Obsidian Version: What is the exact Obsidian version you are using?
  • Network Details: Are/were you by any chance using proxies, VPNs or trying to access Khoj from a firewalled/restricted network (like a university or company network)?

@Sly777
Copy link

Sly777 commented Jan 5, 2025

Hey @debanjum @sabaimran,

I'm also getting CORS error on obsidian side. I'm using cloudflare for security. Everything else related to Khoj is working correctly but sync doesn't work at all.

Khoj: Updating Khoj content index...
index.html:1 Access to fetch at 'https://xx.SERVERNAME.com/api/content?client=obsidian' from origin 'app://obsidian.md' has been blocked by CORS policy: 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.
plugin:khoj:1091 
        
PUT https://xx.SERVERNAME.com/api/content?client=obsidian net::ERR_FAILED 413 (Payload Too Large)
updateContentIndex @ plugin:khoj:1091
await in updateContentIndex (async)
eval @ plugin:khoj:1432
(anonymous) @ app.js:1
plugin:khoj:1091 
        
Uncaught (in promise) TypeError: Failed to fetch
    at updateContentIndex (plugin:khoj:1091:28)
    at async eval (plugin:khoj:1432:39)
updateContentIndex @ plugin:khoj:1091

plugin:khoj:1049 Khoj: Updating Khoj content index...

index.html:1 Access to fetch at 'https://xx.SERVERNAME.com/api/content?client=obsidian' from origin 'app://obsidian.md' has been blocked by CORS policy: 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.
plugin:khoj:1091 
        
PUT https://xx.SERVERNAME.com/api/content?client=obsidian net::ERR_FAILED 413 (Payload Too Large)
updateContentIndex @ plugin:khoj:1091
await in updateContentIndex (async)
eval @ plugin:khoj:1432
(anonymous) @ app.js:1
plugin:khoj:1091 
        
Uncaught (in promise) TypeError: Failed to fetch
    at updateContentIndex (plugin:khoj:1091:28)
    at async eval (plugin:khoj:1432:39)

@huachuman
Copy link
Author

I'm working on a mobile hotspot if that's relevant. latest public obsidian release

@debanjum
Copy link
Member

I see. This line seems like a promising lead:

PUT https://xx.SERVERNAME.com/api/content?client=obsidian net::ERR_FAILED 413 (Payload Too Large)

It indicates the indexing batch size was too large for a single API request.
@huachuman what is the size of the single PDF you'd tried to sync?
Maybe the file size was the main issue and the CORS stuff was throwing us off all along.

If not, than the mobile hotspot/cloudflare proxy should be investigated next.

debanjum added a commit that referenced this issue Jan 12, 2025
debanjum added a commit that referenced this issue Jan 12, 2025
@huachuman
Copy link
Author

I've tried all kinds of things. The size doesn't matter.

@Sly777
Copy link

Sly777 commented Jan 12, 2025

As @huachuman said, the issue is not related to file size because I just tried 2mb pdf file with 60 pages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Fix something that isn't working as expected
Projects
None yet
Development

No branches or pull requests

4 participants