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

fetch in node-appwrite not working using bun #12320

Open
liudonghua123 opened this issue Jul 3, 2024 · 2 comments
Open

fetch in node-appwrite not working using bun #12320

liudonghua123 opened this issue Jul 3, 2024 · 2 comments
Labels
bug Something isn't working needs triage

Comments

@liudonghua123
Copy link
Contributor

What version of Bun is running?

1.1.17

What platform is your computer?

Microsoft Windows [Version 10.0.22631.3810]

What steps can reproduce the bug?

  1. run the following main.ts code using the latest bun via bun main.ts.
  import { Client, Databases, ID, Query } from 'node-appwrite';

  const {
      APPWRITE_ENDPOINT: appwrite_endpoint,
      APPWRITE_FUNCTION_PROJECT_ID: appwrite_function_project_id,
      APPWRITE_API_KEY: appwrite_api_key,
      APPWRITE_DATABASE_ID: appwrite_database_id,
      APPWRITE_COLLECTION_ID: appwrite_collection_id,
  } = process.env;

  async function get_config() {
      console.info(`running create client`)
      const client = new Client()
          .setEndpoint(appwrite_endpoint!)
          .setProject(appwrite_function_project_id!)
          .setKey(appwrite_api_key!);

      console.info(`running create databases`)
      const databases = new Databases(client);
      console.info(`running list documents`)
      const { total, documents } = await databases.listDocuments(
          appwrite_database_id || 'sync_staff_to_wecom_docs',
          appwrite_collection_id || 'dep_to_sheet'
      );
      console.info(`running after databases.listDocuments`)
      console.info(`Found ${total} documents in the collection`);
  }

  await get_config();

What is the expected behavior?

working as expected.

What do you see instead?

just exited when invoke the response = await fetch(uri, options); in node-appwrite.

Additional information

I added some console.info in the implementation of databases.listDocuments. And the same code works using node.

image

Liu.D.H  sync_staff_to_wecom_docs  git(main)   0ms  00:36 > tsx --env-file=.env  main.ts
running create client
running create databases
running list documents
fetch get http://<some-host>/v1/databases/sync_staff_to_wecom_docs/collections/dep_to_sheet/documents {"method":"GET","headers":{"x-sdk-name":"Node.js","x-sdk-platform":"server","x-sdk-language":"nodejs","x-sdk-version":"13.0.0","user-agent":"AppwriteNodeJSSDK/13.0.0 (win32; x64) Node.js/v20.11.1","X-Appwrite-Response-Format":"1.5.0","X-Appwrite-Project":"<some-id>","X-Appwrite-Key":"<some-key>","content-type":"application/json"},"agent":{"_events":{},"_eventsCount":2,"defaultPort":80,"protocol":"http:","options":{"noDelay":true,"path":null},"requests":{},"sockets":{},"freeSockets":{},"keepAliveMsecs":1000,"keepAlive":false,"maxSockets":null,"maxFreeSockets":256,"scheduling":"lifo","maxTotalSockets":null,"totalSocketCount":0},"dispatcher":{"_events":{},"_eventsCount":0}}
fetch response {}
running after databases.listDocuments
Found 2 documents in the collection

Liu.D.H  sync_staff_to_wecom_docs  git(main)   804ms  00:36 > bun main.ts
running create client
running create databases
running list documents
fetch get http://<some-host>/v1/databases/sync_staff_to_wecom_docs/collections/dep_to_sheet/documents {"method":"GET","headers":{"x-sdk-name":"Node.js","x-sdk-platform":"server","x-sdk-language":"nodejs","x-sdk-version":"13.0.0","user-agent":"AppwriteNodeJSSDK/13.0.0 (win32; x64) Bun/1.1.17","X-Appwrite-Response-Format":"1.5.0","X-Appwrite-Project":"<some-id>","X-Appwrite-Key":"<some-key>","content-type":"application/json"},"agent":{"_events":{},"_eventsCount":0,"defaultPort":80,"protocol":"http:","options":{"path":null,"noDelay":true},"requests":{},"sockets":{},"freeSockets":{},"keepAliveMsecs":1000,"keepAlive":false,"maxSockets":null,"maxFreeSockets":256,"scheduling":"lifo","totalSocketCount":0},"dispatcher":{"_events":{},"_eventsCount":0}}

Liu.D.H  sync_staff_to_wecom_docs  git(main)   342ms  00:37 > echo %errorlevel%
-1073740791

Liu.D.H  sync_staff_to_wecom_docs  git(main)   5ms  00:37 >
@liudonghua123 liudonghua123 added bug Something isn't working needs triage labels Jul 3, 2024
@liudonghua123
Copy link
Contributor Author

liudonghua123 commented Jul 3, 2024

@liudonghua123
Copy link
Contributor Author

I found that I can skip this unexpected no-message crash if I comment the following two lines of code in https://github.com/appwrite/sdk-for-node/blob/main/src/client.ts.

// import { createAgent } from 'node-fetch-native-with-agent/agent'; // line 2

//             ...createAgent(this.config.endpoint, { rejectUnauthorized: !this.config.selfSigned }), // line 228

https://github.com/appwrite/sdk-for-node/blob/8113032344a3f29cfd7947cabc14066c7be33320/src/client.ts#L2
https://github.com/appwrite/sdk-for-node/blob/8113032344a3f29cfd7947cabc14066c7be33320/src/client.ts#L228

The first import createAgent is required even createAgent is not used, maybe some overwrites made during the import.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

1 participant