Google Cloud Storage 301 redirect - google-cloud-storage

Weird behavior of Google Cloud Storage. Bucket is configured as website.
When I access subdirectory with '/' (http://example.com/subfolder/) at the end it responds with 200 index.html as expected
When I access subdirectory without '/' (http://example.com/subfolder) it responds with 301 Moved Permanently to http://example.com/subfolder/index.html
Is there any way to avoid this redirect and respond with index.html in both cases?

Related

CORS issue with Ambassador accessing AzureAD

What I have:
a WebApp (ReactJs), an Api (Spring-Boot) each running on a single pod in Kubernetes and an Ambassador wrapped around these (WebApp and Api are having the same domain), my Identity Provider is Azure AD.
In Azure AD I configured a Web-redirect URI for my WebApp.
My Problem:
Accessing the WebApp the first time directs me to microsoft login screen, after entering my credentials I get redirected to my WebApp. When I let the browser tab with my WebApp open, don't use it for 1/1,5 hours and go back and click a button in my WebApp (which triggers a call to my API) I get this CORS error:
Access to XMLHttpRequest at
'https://login.microsoftonline.com/{tenantId}/oauth2/v2.0/authorize?client_id={clientId}&redirect_uri={ambassador-redirectUri}&response_type=code&scope=openid&state={state}'
(redirected from 'https://mydomainname/api/webapp/people') from origin 'https://mydomainname'
has been blocked by CORS policy:
Response to preflight request doesn't pass access control check:
No 'Access-Control-Allow-Origin' header is present on the requested resource
Obviously my access token expired and my application tries to reach the identity provider to get a new one, but my Idp does not allow this.
I followed these steps for setting up Ambassador with Azure AD: https://www.getambassador.io/docs/edge-stack/latest/howtos/sso/azure/ but it seems like I missed something. Anyone a clue what it could be?
The logon flow via the https://login.microsoftonline.com page that you initially experience works only because the URL you want to access (that is, the URL of your WebApp) is in the browser's address bar, hence is used to load a page into the browser tab.
You cannot repeat the same logon flow for an XMLHttpRequest, because this has no address bar and browser tab. Even if the redirection were allowed, the Javascript code of your WebApp could not do anything with the HTML response it would receive from https://login.microsoftonline.com.
If one of your API endpoints (such as https://mydomainname/api/webapp/people) detects that the session is expired, it should not respond with a redirection to https://login.microsoftonline.com, but rather with a specific error code like
HTTP/1.1 403 Forbidden
Content-Type: application/json
{"error": "Session expired",
"redirect": "https://mydomainname/login"}
and when your WebApp receives this, it should present a button to the user labeled
Session expired, press to login again
and pressing this button should open https://mydomainname/login in a new browser tab, which will then automatically redirect to https://login.microsoftonline.com and so on. After the user has closed that tab again, your WebApp can repeat the API request.

How to map / to index.html in AWS API Gateway

I'm using API Gateway as a proxy to fan out requests to different services based on the requested url. For example, /api/${proxy+} is mapped to an EKS cluster with my REST api behind it. But everything that's not under /api is mapped to an S3 bucket with my static files. That's the /${proxy+} part as seen below. It's all working, except that when I request / it returns "Missing Authentication Token." Weird, because /${proxy} doesn't require API tokens or authentication of any kind.
My setup is shown below:
I have tried a variation where I added a method on "/" and return index.html specifically from that S3 bucket

Routing requests to index on Google Storage Bucket

In an attempt to host a (static) SPA app on Google Bucket Storage, I am wondering if it is possible at all, considering a typical SPA have dynamic routes.
For example, in a request to a SPA app:
www.myapp.com/user/jon
You would config the server to route such request to the index.html file,
or else it will throw a 404.
How can I configure Google Bucket to redirect all (even better if I get to specify) requests to the index.html in the bucket?
Have you looked at setting the website metadata attribute in your bucket:
https://cloud.google.com/storage/docs/static-website

CloudCDN bucket: how to set my landing page without domain

I have a Cloud storage bucket with static files in it.
I have set up a load balancer with Cloud CDN enabled on the cloud bucket above.
When I go to the public_IP assigned in the load balancer I get an xml error message access denied as this is just an ip, not a landing page.
When I go to public_ip/index.html, then the website load.
EDIT (removing) :The content of the bucket will only be served by a sub-domain of an external domain name, that's why I can't name my bucket as the domain name.
It is possible to rename a bucket as a subdomain, and the landing page definition works, but the base question remains.
Is there a possibility to set the landing page for the IP address anyhow?
Yes, it's possible to configure a landing page for any Cloud Storage bucket using the gsutil command line tool. For example, the following command configures the landing page for the bucket named elving:
gsutil web set -m index.html gs://elving
Unfortunately, it's not currently possible to configure this using the Google Cloud Console. You must use the API directly or use a tool such as gsutil. You can find more information about gsutil at https://cloud.google.com/storage/docs/gsutil.

Google search showing up the Amazon S3 website link

This is how I set up redirection to the Amazon S3 site:
(Basically followed instructions from here)
Set up a bucket called www.mysite.com and configured it for static website hosting
In my Godaddy account, configured:
Added a CNAME entry for 'www' to point to the publicly accessible S3 site (like mysite.in.s3-website.amazonaws.com)
Added a forwarding rule (302 redirect) to make both mysite.com and www.mysite.com work - whenever someone types in mysite.com, it redirects (browser url bar changes) to www.mysite.com.
Coming to my actual problem - when I do a Google search, the pages are listed under the S3 site ( mysite.in.s3-website.amazonaws.com) - which I'd like to think of as an implementation detail. Is there something else I should do to get google recognize and show links under mysite.com ?