litestar-org / litestar

Production-ready, Light, Flexible and Extensible ASGI API framework | Effortlessly Build Performant APIs
https://litestar.dev/
MIT License
5.53k stars 378 forks source link

Bug: Redirect is not allowed for a preflight request. #3517

Open BrianLYS opened 5 months ago

BrianLYS commented 5 months ago

Description

Having issues with hosting the litestar application with a separate frontend.

Running pnpm run dev with litestar run -r works just fine.

Problem is getting this to production level infrastructure.

In my repository that I've linked, I place a caddy server infront of it and I end up receiving this error.

Access to fetch at 'http://localhost/accounts/login' from origin 'http://localhost:5173' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.

URL to code causing the issue

https://github.com/BrianLYS/sveltekit-litestar-cors-error

MCVE

Access to fetch at 'http://localhost/accounts/login' from origin 'http://localhost:5173' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.

Steps to reproduce

1. Start Caddy, Backend and Postgresql Server with `docker compose up` in root dir 
2. Start frontend server, `cd frontend/app`, `cp .env.example .env`, `pnpm install`, `pnpm run dev`
3. Open localhost:5173 in browser
4. Click register, fill in form.
5. Login with credentials.
6. Inspect console to see error log.

Screenshots

"![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)"

Logs

No response

Litestar Version

2.8.3

Platform


[!NOTE]
While we are open for sponsoring on GitHub Sponsors and OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.

Check out all issues funded or available for funding on our Polar.sh dashboard

  • If you would like to see an issue prioritized, make a pledge towards it!
  • We receive the pledge once the issue is completed & verified
  • This, along with engagement in the community, helps us know which features are a priority to our users.

Fund with Polar

peterschutt commented 5 months ago

Are you interested in submitting a PR @BrianLYS?

BrianLYS commented 4 months ago

@peterschutt a PR to include options method for litestar to pass redirects? I tried to write a custom middleware previously to allow options but I couldn't solve it.

Seems this was brought up before too. https://github.com/orgs/litestar-org/discussions/602