简体   繁体   中英

Firebase rest api Patch request

Hi I'm developing an angular application using firebase, I have to modify the value of a record inside my db and I'm using the rest api:

  this.http.patch(fireBaseConfigDBEndpointCloudReference + this.logIn.getUser().value.id, {
            "name": "",
            "fields": {
                "role": {
                    "stringValue": "pending"
                }
            }
        })

I get the following error:

Access to XMLHttpRequest at ' https://firestore.googleapis.com/v1/projects/project-name/databases/(default)/documents/users/id ' from origin ' http://localhost:4200 ' has been blocked by CORS policy: Method PATCH is not allowed by Access-Control-Allow-Methods in preflight response.

Any idea on how to fix?

As mentioned in the documentation Cross-Origin Resource Sharing (CORS) : "CORS is a mechanism that uses additional HTTP headers to tell browsers to give a web application running at one origin, access to selected resources from a different origin." . This means that this is a way to provide more information via browsers from distinct origins.

Considering the error, it seems that yours is configured to not allow for the endpoint PATCH to be executed. Sometimes this occurs because PATCH is an endpoint to perform partial modifications on the resource - more informationhere .

I would recommend you to check the documentation Configuring CORS , to find more information about it, regarding the use with GCP.

Let me know if the information helped you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM