leepeuker / movary

Self hosted web app to track and rate your watched movies
MIT License
388 stars 14 forks source link

Add support for preflight requests with CORS #581

Closed JVT038 closed 6 months ago

JVT038 commented 6 months ago

While working on the new frontend, I encountered a new problem.

The Movary backend runs on a different address than the frontend. The frontend sends HTTP requests to a different address and due this, we need a proper Cross-Origin-Resource-Sharing (CORS) policy. More info here.

To 'discover' the CORS policy, the browser sends a preflight request. This request is basically asking what methods are allowed for the API endpoint and this PR adds a proper response to the request.

JVT038 commented 6 months ago

I'm closing this, because I think it's better to let Vite act as a proxy.

All the requests to http://frontend/api will be redirected to http://backend/api. This fixes the CORS, because the browser will now send the HTTP request to the host of the frontend and in the background Vite will proxy the request to the movary backend.

If the proxy doesn't turn out to be a good solution after all, we can reopen the PR.