New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Frontend send ajax request to Egg has an error of CORS or OPTIONS 405 Method Not Allowed #45
Comments
The page and the rest api have a different port, so if you request using ajax, server should return It seems the |
@fengmk2 这个是不是放 config,这样可以直接在 config 里覆盖方法了。 |
@popomore Confirmed. It works like charm. Is it a bug in I believe if user turns on cors via |
It is not a bug. We can safely close it and we may need to document it somewhere so that other users do not run into this issue since it is not clear where to configure the whitelist. Here is how I fixed it without modify source code of
|
Why your angular app and rest api are starting at different server, the We should add some view example.
|
Although I know egg server can serve a static webpage, i want to scale my client side and node.js server side separately in two docker containers managed by kubernetes. so that they are not bundled inside a same container as a single process. Kubernetes can handle scale them separately based on the resources. |
Goal: Egg works as simple RESTful api server, Frontend communicates with Egg via Ajax requests. Browser (Chrome latest) has Cross Origin enabled by default. Egg enabled CORS, frontend sends a request and need to get the payload back from Egg.
I have created an Angular frrontend and trying to talk to Egg ONLY via RESTful api. But I run into an issue of CORS. This is the error message from browser console:
I am not sure that it is an error from front end, or egg, or its plugins: egg-rest, egg-cors, or just an User error.
Here is how you can duplicate the issue.
1st Use [examples/restful_api] , then enabled
cors
plugins at [here](https://github.com/eggjs/egg/tree/master/examples/restful_api)(https://github.com/eggjs/egg/blob/master/examples/restful_api/config/plugin.js#L3)Note: it works on
curl
with/withoutcors=true
. and all CRUD operation works as expected.2nd Frontend ajax request: Here I included a simple HTML with jquery ajax caller.
3rd - Load up in the browser, I see the error below:
Error on terminal console
The text was updated successfully, but these errors were encountered: