This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
API-Proxy to prevent CORS-issues #1645
niklaswolf
started this conversation in
Ideas
Replies: 2 comments 2 replies
-
I have used this in another SPA project using Nuxt and It works pretty well. I think it would be a good practice to make this optional if this is possible. Because of the complexity and for users just starting with Shopware-PWA. I think the bigger projects could experience a lot of benefit from this way of preventing CORS. Did u already did some tests to see the results of response time and load on node server? |
Beta Was this translation helpful? Give feedback.
2 replies
-
Hey guys, I have a similar issue. We are using two different domains for the backend and frontend. How can I resolve cors issue. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I already created an issue for this, but I talked with @mkucmus a bit on this and we decided to first have an open discussion about this.
Short summary:
If the Shopware-API lives under a different (sub)domain than the SPA (which is the case for a majority of the projects I believe), a preflight request is made before every api-request because of CORS. This hurts the performance quite bad, because of course the real request has to wait for the preflight request to be finished.
My proposed solution:
Add a nuxt serverMiddleware with a proxy for the shopware-api (in fact there is a dedicated module for this kind of feature @nuxtjs/proxy).
This would add a new server-side route, that can be configured freely, let's say
/store-api
. The configuration would look like this:This would proxy all requests to
/store-api
to the shopware API, with the big difference that there wouldn't be any CORS anymore, as the requested endpoint lives under the same domain as the application itself.Benefits
Drawbacks
Interesting read on the whole topic: https://www.freecodecamp.org/news/the-terrible-performance-cost-of-cors-api-on-the-single-page-application-spa-6fcf71e50147/
Beta Was this translation helpful? Give feedback.
All reactions