1

I am trying to set up a AppEngine flexible (go) backend/api server together with a static frontend.

Ideally i would like to completely decouple the api server from the frontend so was planning to serve all the static files from cloud storage. I have managed to set this up by serving the static files on a subdomain from cloud storage - however, this means that users have to visit the subdomain to retrieve the index.html file.

Does anyone know if it is possible (in e.g. app.yml - but couldnt find anything in the docs here) to get fetch index.html from cloud storage?

I.e. such that:

https://example.com would return index.html from cloud storage https://example.com/api is routed to my appengine service?

Calcopedia
  • 111
  • 1
  • You can have the Go server proxy GCS, for instance: https://golang.org/pkg/net/http/httputil/#NewSingleHostReverseProxy – Peter Aug 09 '18 at 18:35
  • Thanks, thats of course a solution, but the I would not get the cdn advantage of cloud storage and all requests will have to be handled by the server - but if there is no other way i guess i can do that for index at least yes – Calcopedia Aug 09 '18 at 19:46
  • Actually, thinking more about it, this is a good solution, proxying index and having all links in index refer to files at a subdomain – Calcopedia Aug 09 '18 at 19:53

1 Answers1

0

Simply set the "www" subdomain to be your index.html, then let your App Engine handle the request routing. Look into how dispatch.yaml works and you will see how to do it.

Basically, let App Engine route all your default traffic to your index.html and then do the routine specific subdomains to whatever API handlers you have setup.

Ying Li
  • 2,500
  • 2
  • 13
  • 37
  • Im not sure I understand what you are saying - yes i could point the dns for www. to the static files, but that would not help me server @ for the webpage (all visitors would have to use www?) ref dispatch.yaml - I tried to find out but it seems as if it can only forward routes to services, not to cloud storage directly? – Calcopedia Aug 09 '18 at 19:48
  • You won't need GCS in that case, you can serve a static index.html directly from GAE. If you really need GCS to serve your index.html for some reason, you can set it to serve on "www" and then reroute your naked domain to it via [code](https://www.the-swamp.info/blog/google-app-engine-redirection-naked-domain-www/). – Ying Li Aug 09 '18 at 19:54
  • Thanks, i realize that i can serve it from gae, the point of the question was if it could be avoided, wanting to have the to parts fully de-coupled. – Calcopedia Aug 09 '18 at 19:55
  • Yeah, you can but with code. Just setup a redirect code on the naked domain to redirect to your "www" (which is your GCS), then it should work. – Ying Li Aug 10 '18 at 14:34