CORS error when requesting a springboot endpoint using swagger

zizou161TRIAL

a year ago

I deployed my backend on Railway app, I could access swagger without problems, I allowed RAILWAY APP public domain for CORS requests, but I still get this error :

Failed to fetch.
Possible Reasons:

CORS
Network Failure
URL scheme must be "http" or "https" for CORS request.
Am I allowing the correct domain for CORS (the RAILWAY public domain) ?
Is there any additional configuration I should set ?

1 Replies

brunosarti83TRIAL

8 months ago

I was getting this same problem, inspect the network request with the developer tools;

if you are getting "(blocked:mixed-content)" that's because you are making a request to an http url from a https url... you can solve this by forcing a redirect to https, for example in django add these two to your settings.py:

SECURE_SSL_REDIRECT = True

HTTPS SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

or you can also configure swagger to use https instead of http by default (consider that to work in localhost you will still need http)

depending on your framework, now that you know the problem it won't be hard to ask gpt