I'm trying to serve a simple static React SPA through GCP bucket as described here: https://cloud.google.com/storage/docs/hosting-static-website
It is crucial for my structure that for /my_directory
, the file /my_directory/index.html
is served.
I think what I want is exactly described here in the "Three-object bucket" in the documentation
This is my config:
This is my file structure:
In the folder test_2023_11_03_c there is a file "index.html"
But it doesn't work.
For
index.html
served. However, instead I get a list of all files in the bucket.<?xml version='1.0' encoding='UTF-8'?><Error><Code>NoSuchKey</Code><Message>The specified key does not exist.</Message><Details>No such object: my-bucket-name/something-that-doesnt_exist</Details></Error>
<?xml version='1.0' encoding='UTF-8'?><Error><Code>NoSuchKey</Code><Message>The specified key does not exist.</Message><Details>No such object: my-bucket-name/test_2023_11_03_c</Details></Error>
What am I doing wrong?
You are trying to access files without a custom domain. Hence, You are experiencing this behavior. It is stated in the documentation that:
The
MainPageSuffix
andNotFoundPage
website configurations are only used for requests that come to Cloud Storage through a CNAME or A redirect. For example, a request to www.example.com shows the index page, but an equivalent request to storage.googleapis.com/www.example.com does not.Thus,
API
behavior for requests toCloud Storage
domains, such as storage.googleapis.com/www.example.com, is preserved. For example, you can continue to list objects in the www.example.com bucket as you would for any other bucket. In the case of the www.example.com bucket, the object listing you receive includes404.html
andindex.html
Also check this document to set a website configuration for a bucket.