typesense / typesense-dart

Dart client for Typesense
https://typesense.org/docs
Apache License 2.0
73 stars 16 forks source link

ext-firestore-typesense-search-indexToTypesenseOnFirestoreWrite: Request failed with HTTP code 404 | Server said: Not Found #116

Closed rdcoder33 closed 2 years ago

rdcoder33 commented 2 years ago

Hey, I have installed the extension and using the official Typesense cloud to host but I am getting this error from the firebase cloud function when creating new documents:

Flutter Web/ Dart code:

@override
  void initState() {
    const host1 = "wt62ejrukzvh378pp-1.a1.typesense.net";
    const host2 = "wt62ejrukzvh378pp-2.a1.typesense.net";
    const host3 = "wt62ejrukzvh378pp-3.a1.typesense.net";
    const protocol = Protocol.http;
    final config = Configuration(
      // Replace with your configuration
      '[admin key (removed on github for security reasons)]',
      nodes: {
        Node(
          protocol,
          host1,
          port: 443,
        ),
        Node(
           protocol,
          host2,
          port: 443,
        ),
        Node(
          protocol,
          host3,
          port: 443,
        ),
      },
      numRetries: 3, // A total of 4 tries (1 original try + 3 retries)
      connectionTimeout: const Duration(seconds: 10),
    );
    client = Client(config);

    super.initState();
  }

Below are the screenshots for the extension configuration and firebase functions log:

WhatsApp Image 2022-03-13 at 12 09 24 WhatsApp Image 2022-03-13 at 12 11 25

happy-san commented 2 years ago

Seems like an issue with the firebase extension.

cc: @jasonbosco @kishorenc

happy-san commented 2 years ago

@rdcoder33 Could you share the exact reproduction steps?

More specifically: The dart code you're using to write documents.

jasonbosco commented 2 years ago

Could you make sure you've created a collection called "3d_icons" in Typesense? The Firebase extension doesn't create the collection for you - it only syncs documents within a collection.

rdcoder33 commented 2 years ago

Could you make sure you've created a collection called "3d_icons" in Typesense? The Firebase extension doesn't create the collection for you - it only syncs documents within a collection.

oh didn't know that. Indexing functions work now but got a Error: XMLHttpRequest error

when searching.

searching code in Flutter Web / Dart:

  searchTypeSense() async {
    Map<String, String> search = {
      'q': 'kid',
      'query_by': 'tags',
    };
    client.collection("3d_icons").documents.search(search);
  }

Client Config is same as above (first comment)

jasonbosco commented 2 years ago

@rdcoder33 Could you try doing the same API call using curl and see if you're able to replicate the issue?

rdcoder33 commented 2 years ago

@rdcoder33 Could you try doing the same API call using curl and see if you're able to replicate the issue?

It works on curl:

typesense

But for the same request and parameters on dart client (pub.dev plugin) is shows following error:

dart-sdk[/lib/async/stream.dart]() 1288:7 dart-sdk[/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart]() 334:14 _checkAndCall dart-sdk[/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart]() 339:39 dcall dart-sdk[/lib/html/dart2js/html_dart2js.dart]() 37301:58 at Object.createErrorWithStack ([http://localhost:49794/dart_sdk.js:5080:12]()) at Function._throw ([http://localhost:49794/dart_sdk.js:20337:18]()) at Function.throwWithStackTrace ([http://localhost:49794/dart_sdk.js:20334:18]()) at async._AsyncCallbackEntry.new.callback ([http://localhost:49794/dart_sdk.js:40851:18]()) at Object._microtaskLoop ([http://localhost:49794/dart_sdk.js:40708:13]()) at _startMicrotaskLoop ([http://localhost:49794/dart_sdk.js:40714:13]()) at [http://localhost:49794/dart_sdk.js:36191:9]()

I am testing this on flutter web.

jasonbosco commented 2 years ago

@happy-san Any thoughts on this ^

rdcoder33 commented 2 years ago

this might help:

https://stackoverflow.com/questions/69115713/how-can-i-solve-xmlhttprequest-error-with-flutter

happy-san commented 2 years ago

Hi, @rdcoder33 this seems to be a web-specific issue. Looking around I found these links: Hope you'll give them a try.

https://stackoverflow.com/a/66879350/11218270 https://pub.dev/packages/flutter_cors

1- Go to flutter\bin\cache and remove a file named: flutter_tools.stamp 2- Go to flutter\packages\flutter_tools\lib\src\web and open the file chrome.dart. 3- Find '--disable-extensions' 4- Add '--disable-web-security'

happy-san commented 2 years ago

Since this is a separate issue from what you opened, I'd recommend opening a new issue for future reference.

rdcoder33 commented 2 years ago

https://pub.dev/packages/flutter_cors

This doesn't solve the problem for me. Same error

happy-san commented 2 years ago

@rdcoder33 Can you share the exact response you're receiving from the server?

Specifically the response headers.

happy-san commented 2 years ago

Hi @rdcoder33 Did you resolve XMLHttpRequest error?

rdcoder33 commented 2 years ago

Ohh sorry for the late reply. Nope, it didn't get solved so we opted for the HTTP request to type sense API rather than using the flutter plugin.

happy-san commented 2 years ago

@rdcoder33 Would you care to correspond with me in figuring out a fix?

rdcoder33 commented 2 years ago

@rdcoder33 Would you care to correspond with me in figuring out a fix?

I would love to but kinda a busy currently. I will send you the details of the issue by tomorrow (it's nighttime in India) and will try to correspond probably after 2-3 days.

I hope this works for you?

happy-san commented 2 years ago

Sure that'll be great. I'm in the same timezone.