inventree / InvenTree

Open Source Inventory Management System
https://docs.inventree.org
MIT License
4.32k stars 781 forks source link

API Request returns "Not Found" #7141

Closed VanCalsterFinn closed 6 months ago

VanCalsterFinn commented 6 months ago

Deployment Method

Describe the problem*

I followed all the steps to setup an Inventree Production instance and it is running perfectly. I also created an admin account after the installation, as suggested in the documentation. However i ran into an issue when trying to communicate with Inventree from a Laravel application running on the same device and domain. I am trying to request an Inventree API Token from my Laravel application. The Laravel application is hosted at "http://localhost:8080". In the .env file of Inventree, i've changed the INVENTREE_SITE_URL to "http://localhost". Both applications are running fine. From my laravel application I am trying to call this API: $response = Http::withBasicAuth($username, $password)->get("http://localhost/api/user/token/"); I have checked multiple times that the credentials are correct and that the syntax of the API call is correct too, Ive copied it straight from the api-docs provided by Inventree. In relevant log output, i have included the response from the API attempt. When i attempt to call the API, i don't get any output in the inventree docker container either. if my Laravel application is making a request to http://localhost/api/user/token/, it should be handled by Caddy and reverse proxied to the Inventree server container. But this does not seem to happen since there are no logs. I am lost. Is there anything i've missed? Thanks in advance!

Steps to Reproduce

  1. https://docs.inventree.org/en/stable/start/docker_install/
  2. Follow all the steps in the docker install guide, including creating the superuser account.
  3. In the .env file change the INVENTREE_SITE_URL to 'http://localhost'
  4. Start the docker containers with 'docker compose up -d'
  5. From a Laravel application hosted at 'http://localhost:8080' call the API via: $response = Http::withBasicAuth($username, $password)->get("http://localhost/api/user/token/"); dd($response); // Make sure the username and password are the correct credentials to the superuser.

Relevant log output

Illuminate\Http\Client\Response {#335 ▼ // app\Http\Controllers\LoginController.php:32
  #response: GuzzleHttp\Psr7\Response {#371 ▼
    -reasonPhrase: "Not Found"
    -statusCode: 404
    -headers: array:4 [▶]
    -headerNames: array:4 [▶]
    -protocol: "1.1"
    -stream: GuzzleHttp\Psr7\Stream {#367 ▶}
  }
  #decoded: null
  +cookies: GuzzleHttp\Cookie\CookieJar {#352 ▶}
  +transferStats: GuzzleHttp\TransferStats {#372 ▼
    -request: GuzzleHttp\Psr7\Request {#358 ▼
      -method: "GET"
      -requestTarget: null
      -uri: GuzzleHttp\Psr7\Uri {#354 ▼
        -scheme: "http"
        -userInfo: ""
        -host: "localhost"
        -port: null
        -path: "/api/user/token/"
        -query: ""
        -fragment: ""
        -composedComponents: "http://localhost/api/user/token/"
      }
      -headers: array:3 [▼
        "User-Agent" => array:1 [▶]
        "Authorization" => array:1 [▶]
        "Host" => array:1 [▶]
      ]
      -headerNames: array:3 [▶]
      -protocol: "1.1"
      -stream: GuzzleHttp\Psr7\Stream {#357 ▶}
    }
    -response: GuzzleHttp\Psr7\Response {#371 ▶}
    -transferTime: 0.00125
    -handlerStats: array:39 [▶]
    -handlerErrorData: 0
  }
}
matmair commented 6 months ago

This soudns like a question for Stackoverflow, not a deployment issue with InvenTree.

SchrodingersGat commented 6 months ago

Did you confirm that you can access http://localhost/api/user/token/ via another method such as a web browser or CURL?

VanCalsterFinn commented 6 months ago

I got access through direct web browser url, but not via laravel Http client, altough it worked with the previous version of inventree, when the docker install was cloning github and a couple docker commands without the caddyfile. Im unsure if it has anything to do with the domains, using inventree.localhost or just localhost, i tried both, but it doesnt change anything.