-
-
Save ashgkwd/a3c412e4f0c0c38c352683c7f25bce37 to your computer and use it in GitHub Desktop.
DOMAIN_NAME="my.web.site"; | |
PROJECT_ID="my-gcp-project-id"; | |
# create bucket of domain name | |
gsutil mb -p $PROJECT_ID -b on gs://$DOMAIN_NAME | |
# set index file | |
gsutil web set -m index.html gs://$DOMAIN_NAME | |
# set error file | |
gsutil web set -e 404.html gs://$DOMAIN_NAME | |
# permissions: let the world see our files ๐ | |
gsutil iam ch allUsers:legacyObjectReader gs://$DOMAIN_NAME | |
# deploy files to bucket | |
gsutil -m rsync -d -r local/path/of/site gs://$DOMAIN_NAME |
In the case of React and other websites which need to load index.html
on any non-available file path, you can set 404 to respond with index.html. That way if the user reloads on some URL on your website, it will get index.html. This is especially helpful when routes are handled inside the application. The rest of the static files (images, CSS, js etc) will continue to be served as is.
gsutil web set -e index.html gs://$DOMAIN_NAME
Hey @ashgkwd!
YouTube blocks comments with URLs in them, but if you want to comment again that you created this gist, I can add a link in a reply!
Also, FYI i have the code in the repo for my channel here as well: https://github.com/sidpalas/devops-directive/blob/master/2020-09-28-gcs-cloudflare-static-site/create-bucket.sh
Hey @sidpalas ๐, It will be nice if you comment the link. I did not know that YouTube blocks links ๐. Thanks
๐ -- if you add your comment back on youtube (without link) ill reply with the link ๐
You can refer to this great video to understand DNS and other configs needed for GCS bucket websites to work: https://www.youtube.com/watch?v=sUr4GBzEqNs