itzg / docker-minecraft-bedrock-server

Containerized Minecraft Bedrock Dedicated Server with selectable version
MIT License
1.14k stars 219 forks source link

Unknown errors using `@minecraft/server-net`. #436

Open smell-of-curry opened 3 months ago

smell-of-curry commented 3 months ago

No response, when sending HTTP Request using Script API Inside the docker container.

Hey, recently I have been trying to use Script API to send an HTTP Request to fetch a database inside Minecraft Bedrocks Script API Which is inside a docker container using itzg/docker-minecraft-bedrock-server. I know my code works well, as I have used it before outside the docker container. Here is a small snippet of the code here:

  /**
   * Sends a request to create a table
   * @param tableName
   */
  static async createTable(tableName: string): Promise<number> {
    try {
      const secret = secrets.get("databaseToken");
      if (!secret) throw new Error(`[DATABASE]: No database token found!`);

      const uri = `${DATABASE_HOST}:${DATABASE_PORT}/api/database/${DATABASE_NAME}/table/${tableName}/create`;
      const res = new HttpRequest(uri);
      console.log(`[DATABASE] Creating table: ${tableName}, to: "${uri}"!`);
      res.setMethod(HttpRequestMethod.Post);
      res.setHeaders([new HttpHeader("authorization", secret)]);
      const response = await http.request(res);

      console.warn(
        `[DATABASE]: Table: ${tableName} created, status: ${response.status}!`
      );
      return response.status;
    } catch (error) {
      console.warn(`[DATABASE]: Failed to create table: ${tableName}, ${error}!`)
      return 404
    }
  }

As you can see, its sending a HTTP Post request to an endpoint and waiting for a response. However, when you look at the logs for the server it says this

[2024-07-11 13:01:28:284 INFO] [Scripting] [DATABASE]: Creating new database instance for table: entities!

[2024-07-11 13:01:28:284 INFO] [Scripting] [DATABASE] Creating table: entities, to: "http://host.docker.internal:3000/api/database/testing/table/entities/create"!

No response is ever given, and it just stays blank. Additionally, when I go to look at the database logs, nothing has come through. So I am guessing that somewhere the HTTP Request is getting lost or deleted. However when I look at the NGINX logs for my database, it shows that my request getting sent never comes through, but another request with a return of 408 is sent.

2024-07-11 09:32:02 172.20.0.1 - - [11/Jul/2024:13:32:02 +0000] "POST /api/database/testing/table/entities/create HTTP/1.1" 408 25 "-" "libhttpclient/1.0.0.0"

I'm very confused with what is going on. I feel like something inside the docker container is blocking it. I know it's not the network because inside my docker-compose I have a proxy system that is able to connect to the database the same way which is using Go-http-client as shown below

2024-07-11 09:29:07 172.20.0.1 - - [11/Jul/2024:13:29:07 +0000] "GET /api/database/testing/table/entities HTTP/1.1" 200 463 "-" "Go-http-client/1.1"

Please help me figure out whats going on, and if this is something to do with the image.

itzg commented 3 months ago

As mentioned in Discord, I don't see how this a fault my image startup script. I don’t have the time or expertise to help with whatever you’re seeing.