Haidra-Org / AI-Horde

A crowdsourced distributed cluster for AI art and text generation
GNU Affero General Public License v3.0
1.06k stars 127 forks source link

CORS issue #22

Closed leszekhanusz closed 1 year ago

leszekhanusz commented 1 year ago

I'm trying to implement the Stable Horde API for the diffusion-ui frontend.

Using the https://stablehorde.net/api/v2/generate/sync endpoint, my POST data looks like this:

  {
    "payload": {
        "sampler_name": "k_lms",
        "batch_size": 1,
        "cfg_scale": 7,
        "seed": -1,
        "height": 512,
        "width": 512,
        "steps": 50,
        "n": 1
    },
    "prompt": "a horde of cute stable robots in a sprawling server room repairing a massive mainframe",
    "nsfw": false,
    "censor_nsfw": false
  }

It seems I was able to receive a few images, but now sometimes I receive the following error:

Access to fetch at 'https://stablehorde.net/api/v2/generate/sync' from origin 'http://localhost:5173' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
leszekhanusz commented 1 year ago

It seems the error is returned about 3 minutes after the request has been made.

db0 commented 1 year ago

Any idea what header I need to allow to fix this?

leszekhanusz commented 1 year ago

Access-Control-Allow-Origin: *

db0 commented 1 year ago

It seems I'm already allowing that: https://github.com/db0/AI-Horde/blob/main/horde/__init__.py#L33

db0 commented 1 year ago

I've put the header in my reverse proxy as well. Maybe it will work for you now?

leszekhanusz commented 1 year ago

No, here is my console.log value:

Access to fetch at 'https://stablehorde.net/api/v2/generate/sync' from origin 'http://localhost:5173' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains multiple values '*, *', but only one is allowed. Have the server send the header with a valid value, or, if an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

It immediately fails every time now.

db0 commented 1 year ago

welp! OK removed it from apache. Did it stop failing immediately now?

leszekhanusz commented 1 year ago

Yes, it seems to work again.

db0 commented 1 year ago

But still randomly failing?

db0 commented 1 year ago

Anyway, I suggest you use async instead, as it will allow you to get the status of the request while waiting as well

leszekhanusz commented 1 year ago

But still randomly failing?

Difficult to know. It was failing previously when the number of workers were low and after 3 minutes. It seems to work correctly right now. I suspect it fails only when it has to send an error.

leszekhanusz commented 1 year ago

Anyway, I suggest you use async instead, as it will allow you to get the status of the request while waiting as well

Yes, I was planning to switch to async once it works correctly in sync mode.

db0 commented 1 year ago

It sounds like it was failing because the request was expiring. It should be better now as I increased the expiry timeout to give more time during high load. Async would avoid the connection ending like that and you would get more info