It does this via a preflight exchange of headers with the target resource. Her is how launchSettings.Cross-Origin Resource Sharing (CORS) is a protocol for relaxing the Same-Origin policy to allow scripts from one domain (Origin) to access resources at another. LaunchSettings.json have a section called Docker ponting to swagger, I’m just thinking about swaping swagger for api I’ve just noticed something at launSettings.json (I haven0t tried yet to create a new docker container), if I let Visual Studio create a model Net 6 API with Docker support (mine I started without and later I added Dockerfile) I’ve seen there is Net 7 around (not yet Linux version) Yet seems API is not taking care of those, or maybe CORS policies are rewritten by an external service In the code I have app.UseCors(x => x.AllowAnyOrigin() I tried with 172.17.0.1 since ifconfig was shoing me that IPĪt this point I think is the same Net 6 API that even when I’m applying CORS maybes is not working properly To allow everyone (you should probably NOT do that): Access-Control-Allow-Origin: * Pplication might be running on :443/… and your api on :6001/… the API has to send som header-information telling the browser that it is OK to be called from 443/… and the browser will then be happily accepting the API’s response. If might be easier if you have all containers needed for your service within the same Docker-network - then you should also be able do access the other container’s service using the container’s name without exposing this container’s port(s) to the outside world (maybe useful for a database in a productive environment). ![]() So if you want to connect from within a Docker-container to a service on the physical computer’s localhost you have to use 172.17.0.1 (on Linux it is the default-host-ip-address within Docker’s default network) or (on Windows-machines). Maybe another pitfall when moving a service working on a physical computer into a container:Ī Docker-container’s localhost is not the same as your physical computer’s localhost. ![]() It is one request to and hopefully a successful response. If you use Postman to directly access the API there is no CORS-checking involved. You wrote that you have added a CORS-header to your API’s responses to allowed all URLs to acces this API - but according to the errormessage your browser has a different opinion on this topic So if your Angular-application might be running on and your api on the API has to send som header-information telling the browser that it is OK to be called from and the browser will then be happily accepting the API’s response. This is a error-message created by your browser, not by the API-container, because protocol, host and port have to be identical (see see: Same Origin Policy - Web Security) to allow access from JavaScript (that is what Angular is : a JavaScript/TypeScript-frontend-framework) or you have to add information to your API’s response-header. ![]() I do not find documentation on official MIcrosoft / Docker webpages about this kind of CORS situation and I do sincerily believe that is a recurrent error Yet I do have CORS allowing any origin on API sideĪlso note that when running from linux console (out of Docker) postman then return the results, yet Angular still giving CORS error I doubt being problem of sql docker container, since the error that gives angular isĬross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at (Reason: CORS request did not succeed). ![]() I can always start a virtualmachine with windows and work there, but I want to avoid that Just I work mainly under Linux OS, hence I prefer to have all my things running on it I can connect to SQL Server machine with Azure Data StudioĪll is in my home machine, is a personal/home dev enviornment Both containes are answering from localhost and are hosted in the same machine
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |