简体   繁体   中英

Serve a React app from Google Cloud Storage

I am trying to serve a React app from Google Cloud Storage. I built the React project and uploaded the contents of the build/ directory to Google Cloud Storage. I made sure every file inside is publicly accessible. However when I go to my Google Cloud bucket link http://storage.googleapis.com/BUCKET_NAME/ , I get some XML about a permission error:

Then, I tried to navigate to the URL http://storage.googleapis.com/BUCKET_NAME/index.html , which brings up a blank page

First of all, I'd definitely suggest using firebase hosting, instead if cloud storage, it's made for hosting static websites, and I've used it with a react app and it's working quite fine for me.

It'd be helpful if you can share the error message you received.

You can try the following (Not sure it'll work, given that you haven't provided the error message, but it's worth a shot)

You can try editing the rules, to disable authentication for browsing the files in that bucket.

In your firebase console, go to Storage , choose you bucket, Rules tab, Edit Rules

you can try to change from

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}

to

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if true;
    }
  }
}

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