admin管理员组

文章数量:1393900

Im running a site with google firebase. Our github repo makes a preview deployment when we make a PR. I would like to have those temporary build urls to be approved by cors. Here is what I have in the cors.json that I pushed, but its not working.

  {
    "origin": [
      "http://localhost:5173", // Local dev
      ";, // The live site
      "https://my-site-*--pr*.web.app" // The pr preview sites
    ],
    "method": ["GET", "POST", "PUT"],
    "maxAgeSeconds": 3600
  }
]

So when I use the wildcards in the address, it doesnt work. If I add that specific build url to the file and deploy it, then the build site will have access. But I dont want to update the cors policy for every PR.

I tried doing some research but could not find the docs for cors rulesets.

Deployment of the cors policy follows the comments found here Firebase Storage and Access-Control-Allow-Origin. The json file is deployed to the project using Google's gsutil.

Im running a site with google firebase. Our github repo makes a preview deployment when we make a PR. I would like to have those temporary build urls to be approved by cors. Here is what I have in the cors.json that I pushed, but its not working.

  {
    "origin": [
      "http://localhost:5173", // Local dev
      "https://my-site.app", // The live site
      "https://my-site-*--pr*.web.app" // The pr preview sites
    ],
    "method": ["GET", "POST", "PUT"],
    "maxAgeSeconds": 3600
  }
]

So when I use the wildcards in the address, it doesnt work. If I add that specific build url to the file and deploy it, then the build site will have access. But I dont want to update the cors policy for every PR.

I tried doing some research but could not find the docs for cors rulesets.

Deployment of the cors policy follows the comments found here Firebase Storage and Access-Control-Allow-Origin. The json file is deployed to the project using Google's gsutil.

Share Improve this question edited Mar 28 at 23:19 Doug Stevenson 318k36 gold badges456 silver badges473 bronze badges Recognized by Google Cloud Collective asked Mar 27 at 14:04 knightwatchknightwatch 1833 silver badges10 bronze badges 5
  • Are you deploying to Firebase Hosting? If so, there is nothing in the documentation that suggest you can deploy a file called "cors.json" that affects the way Firebase works. There is a mention in the documentation for the configuration that you can set CORS headers for resources. – Doug Stevenson Commented Mar 28 at 16:04
  • @DougStevenson The name of the file is irrelevant. You just need to push a json file to the google gsutils – knightwatch Commented Mar 28 at 16:59
  • So you're not using Firebase Hosting, and instead something else you haven't mentioned? I guess I don't understand then how you are deploying this content. Please edit the question to explain in more detail what you're doing for deployment, including the gsutil command that you think should work. Also include what you're doing that checks that the behavior is not what you expect. We should be able to duplicate the unexpected behavior using the instructions you provide. – Doug Stevenson Commented Mar 28 at 17:00
  • @DougStevenson We are using Firebase Hosting, I'm just using gsutil to push the cors policy to the Firebase project. I added some extra info which hopefully should help. – knightwatch Commented Mar 28 at 18:48
  • Firebase Storage is not the same as Firebase Hosting. They are different completely different products that don't overlap at all. Are you still sure you're deploying to Firebase Hosting, then? If you're using gsutil, you are almost certainly not using Firebase Hosting. So, what exactly are you doing (not what someone else is doing)? Please edit the question to show the specific steps you're taking with instructions on how we can duplicate them to observe the same result. – Doug Stevenson Commented Mar 28 at 23:16
Add a comment  | 

1 Answer 1

Reset to default 0

As you mentioned it works whenever you include the proper PR/Build url, it seems the problem is with the pattern you inserted.

You can try using this regex, for example, considering the changing data in the URL will be non numeric:

/https:\/\/my-site-[A-Za-z]+--pr[A-Za-z]+\.web\.app/g

本文标签: firebaseHandling CORS origin sites with wildcard in urlStack Overflow