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
localhost dev mode can't access backend api because of cors #1408
Comments
it will be fixed in my case if i change code like this const (
headerOrigin = "Origin"
headerAllowOrigin = "Access-Control-Allow-Origin"
headerAllowMethods = "Access-Control-Allow-Methods"
headerAllowHeaders = "Access-Control-Allow-Headers"
headerAllowCredentials = "Access-Control-Allow-Credentials"
)
func CorsFilter(ctx *context.Context) {
origin := ctx.Input.Header(headerOrigin)
originConf := conf.GetConfigString("origin")
if origin == originConf {
ctx.Output.Header(headerAllowOrigin, origin)
ctx.Output.Header(headerAllowMethods, "POST, GET, OPTIONS")
ctx.Output.Header(headerAllowHeaders, "Content-Type, Authorization")
ctx.Output.Header(headerAllowCredentials, "true")
if ctx.Input.Method() == "OPTIONS" {
ctx.ResponseWriter.WriteHeader(http.StatusOK)
}
return
}
// if origin != "" && originConf != "" && origin != originConf {
// if object.IsAllowOrigin(origin) {
// ctx.Output.Header(headerAllowOrigin, origin)
// ctx.Output.Header(headerAllowMethods, "POST, GET, OPTIONS")
// ctx.Output.Header(headerAllowHeaders, "Content-Type, Authorization")
// } else {
// ctx.ResponseWriter.WriteHeader(http.StatusForbidden)
// return
// }
// if ctx.Input.Method() == "OPTIONS" {
// ctx.ResponseWriter.WriteHeader(http.StatusOK)
// return
// }
// }
} |
@SealinGp Hi, may I ask which release version did you clone? |
Hi @SealinGp , I tried to replicate the issue locally(win10) but mine seems to be working fine with all the recent commits in the master branch. I have searched online for relevant solutions, maybe you could also look at this extension Allow CORS: Access-Control-Allow-Origin to resolve the issue instead of changing the code directly? Moreover, would you mind seeing if you could successfully deploy earlier commits? |
your origin conf is empty ? can you show me the origin config value ? |
yes,
|
maybe you should start web server to access the page, then you can get this error, i still got the same error using your config file. the below operation previous required: here are my steps to start web dev server(after installed nvm-windows).
export const ServerUrl = "http://localhost:8000";
# assume you located in /xxx/casdoor dir
pwd=$PWD
cd $pwd/web && nvm install v16.10.0 && nvm use v16.10.0 && npm install --global yarn && yarn install && yarn start then access http://localhost:7001/ and press F12 to see the console log |
Hi @SealinGp , yup I started the frontend & backend service using the commands as shown below. Doesn't seem to have this error. I installed Go 1.6+, Node.js LTS (16 or 14), and Yarn 1.x |
i'm confused. can i see your web/src/Setting.js file content ? |
@SealinGp okay I now can replicate the error and have found the key part. In web/src/Setting.js, if the |
i figure it out, just shutdown the local nginx server will be normal. thanks for your help. ^_^ |
No problem! 👍 |
i follow the https://casdoor.org/docs/basic/server-installation for local dev .then i got this cors error.
my app.conf file content
The text was updated successfully, but these errors were encountered: