简体   繁体   English

从 Google Cloud Storage 提供 React 应用程序

[英]Serve a React app from Google Cloud Storage

I am trying to serve a React app from Google Cloud Storage.我正在尝试从 Google Cloud Storage 提供 React 应用程序。 I built the React project and uploaded the contents of the build/ directory to Google Cloud Storage.我构建了 React 项目并将 build/ 目录的内容上传到 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:但是,当我转到我的 Google Cloud 存储桶链接http://storage.googleapis.com/BUCKET_NAME/ 时,我收到了一些关于权限错误的 XML:

Then, I tried to navigate to the URL http://storage.googleapis.com/BUCKET_NAME/index.html , which brings up a blank page然后,我尝试导航到 URL http://storage.googleapis.com/BUCKET_NAME/index.html ,这会显示一个空白页面

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.首先,我绝对建议使用 firebase 托管,而不是云存储,它是为托管静态网站而设计的,我已经将它与 react 应用程序一起使用,对我来说效果很好。

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在您的 Firebase 控制台中,转到Storage ,选择您的存储桶、规则选项卡、编辑规则

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;
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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