1

I have an Ionic PWA, so it runs in browser. I'm trying to send requests to my symfony backend. At first I had everything installed on my local pc and the requests were working with an ionic proxy. Now I have installed both applications on a server. At first I have tried to use the url from the backend without proxy. Then there was a CORS error. Then I wrote a .htaccess file for the backend with the following input:

Header add Access-Control-Allow-Origin "\*"
Header add Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"

Now I'm getting this:

XMLHttpRequest cannot load ... Response for preflight has invalid HTTP status code 405

If I set a proxy as before on the local installation like this:

"proxies": [
    {
      "path": "/api",
      "proxyUrl": "http://api.example.com/api"
    }
  ]

I'm getting a 404 not found error, when I try to send a request to http://app.example.com/api

Can someone tell me how it will work correctly when frontend and backend are on a server and the app runs in the browser?

1 Answer 1

1

If you're getting a 405 back, that's a method not supported error, so it looks like you server isn't configured to handle OPTIONS requests. That's causing the pre-flight CORS request to get rejected.

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, but I have OPTIONS in my .htaccess, like you see above. Or must I do it on a different way?
You're only adding a response header above. It looks like the problem is your server isn't configured to accept OPTIONS requests. See this other answer: stackoverflow.com/questions/43696369/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.