mrhan1993 / FooocusAPI

Fooocus with fastapi
https://mrhan1993.github.io/docs
GNU General Public License v3.0
15 stars 4 forks source link

[Bug]: Inaccessible Generated Images from API (Behind a Load Balancer + API Key) #20

Closed ldavis9000aws closed 1 month ago

ldavis9000aws commented 1 month ago

Checklist

What happened?

Generated image URLs include a port number, causing them to fail when accessed behind a load balancer that exposes only ports 80 and 443. Removing the port number from the URL results in a 403 Forbidden error due to the requirement of a custom x-api-key header. Disabling the API key option allows image access without the port number.

image

Steps to reproduce the problem

  1. Start the API using the following command: python launch.py --listen 0.0.0.0 --port 8888 --base-url fooocusapi.your-url.com --apikey %fooocus-apikey% --debug-mode --nowebui

  2. Generate an image using the API.

  3. Attempt to access the generated image URL with the port number behind a load balancer (ports 80 and 443).

  4. Remove the port number from the URL and attempt to access the image.

What should have happened?

Direct access to the generated image via URL without requiring a port number or custom header.

What browsers do you use to access Fooocus?

Google Chrome, Microsoft Edge

Where are you running Fooocus?

Cloud (other)

What operating system are you using?

No response

Console logs

INFO:     10.0.13.1:41688 - "GET /outputs/2024-07-11/2024-07-11_18-57-43_5837.png HTTP/1.1" 403 Forbidden
INFO:     127.0.0.1:52007 - "GET /outputs/2024-07-11/2024-07-11_18-57-43_5837.png HTTP/1.1" 403 Forbidden

Additional information

What I'd like to see:

Remove the Port Number from Image URLs: Ensure the FastAPI backend generates image URLs without including the port number, to maintain compatibility with load balancers exposing only ports 80 and 443.

Allow Image Retrieval without API Key: Adjust the FastAPI configuration to allow public access to image retrieval endpoints without requiring the x-api-key header, while maintaining API key protection for all other operations.

I'd like the URL retrieval to work like it did originally by only requiring API keys for all other endpoints except the retrieval of images. This will keep the API operations secure while allowing easier access for users.

mrhan1993 commented 1 month ago

An update will be soon

mrhan1993 commented 1 month ago

An update has pushed, I removed auth for output, and you can by pass API_PORT to specify the api port