
Use App Engine and Go to Host a Static Website with Same Domain Redirects - aliasnexus0
https://thornelabs.net/2017/03/08/use-google-app-engine-and-golang-to-host-a-static-website-with-same-domain-redirects.html
======
PuffinBlue
This is well done.

If you want it 'done for you' or have a site that doesn't fit in the free tier
on GAE but don't want to spend money - take a look at Netlify.

Free tier is generous, has CDN, free auto-provisioned SSL, builds
automatically from a git repo (GitHUb/GitLab etc) and you can simply upload a
_redirects file to handle redirects[0].

It'll even build a 'preview' of a branch, so just create a branch, make your
changes and merge request, then Netlify will build a temporary site to view
the changes - useful if you need to show someone what the changes to the site
will look like.

I just switched from GitLab pages, and even changed domain from the apex to
www (to get full DDoS/CDN benefit out of Netlify this is needed) - which is
handled automatically.

If you want to have a poke around/speedtest of a site using it I'll link
below[1].

[0]
[https://www.netlify.com/docs/redirects/](https://www.netlify.com/docs/redirects/)

[1] [https://www.josharcher.uk](https://www.josharcher.uk)

------
chrisp_dc
I host my static website using Firebase and Google Domains. Google has easy
integration between the two and seems to include all the listed benefits out-
of-box.

------
tyingq
Thrifty way to do this. Seems the golang code, though, isn't setting any
expires or cache-control headers (for the static content it's serving), so
your browser ends up re-downloading a lot of assets that it doesn't need to.

Might be nice to add that bit in. Better performance for visitors, and would
keep you in the free tier longer if traffic grows.

~~~
aliasnexus0
You are correct, and great points. This is my first Golang app, so doing what
you suggested is my next step. Thanks!

------
grw_
The app.yaml routing allows "fall-through" routing, where your application's
handler is only invoked if no static files match:

    
    
      - url: /static
        static_dir: static/
      - url: /.*
        script: _go_app
    

The redirect 'map' smells bad- better to simply serve the file if path exists,
redirect if it doesn't.

------
briandoll
Or just use Netlify: [https://www.netlify.com/](https://www.netlify.com/)

~~~
StavrosK
Seconded, lately I've been using Lektor+netlify for all my sites. Deploying is
just a git push, and it's zero-headache. Greatly recommended.

------
nodesocket
Heads up Google Cloud just release a new feature today which allows you to
redirect traffic to different storage buckets and even VM instances using
simple rules which are themselves stored in a storage bucket.

[https://cloud.google.com/compute/docs/load-
balancing/http/us...](https://cloud.google.com/compute/docs/load-
balancing/http/using-http-lb-with-cloud-storage?utm_source=release-
notes&utm_medium=email&utm_campaign=2017-March-release-notes-1-en)

------
caleblloyd
My recommendation to a friend for static hosting would be to use shared
hosting for $5/mo.

Pick one that does automatic SSL with LetsEncrypt. I'm partial to Dreamhost
because I've been on them for many years, but there are lots of good ones out
there.

~~~
kej
I know $5/month isn't all that much, but I still like to suggest Nearly Free
Speech. Most static sites can be hosted for pennies per month.

------
bjpirt
Or even simpler you can use S3 redirects to send all of your old URLs to their
new location on the same host. I'm currently doing this from both an old
domain to a new domain and within the same domain and "It Just Works" (tm)

~~~
tapirl
app engine static files are dispatched by google cdn network for free.
CloudFront is not free.

~~~
tyingq
I think the OP is subverting the CDN functionality since the static assets are
flowing through the golang code.

~~~
tapirl
not flowing through, it is redirecting. The static files are really served by
google cdn.

~~~
tyingq
I don't think so. See his code:

    
    
        http.ServeFile(w, r, "static/"+r.URL.Path)

~~~
tapirl
ok, he could use google cdn in fact.

------
james_niro
I prefer Heroku over google cloud, better documentation and deploying is
really easy.

~~~
PuffinBlue
Any time I hear 'Heroku' it's mentally followed by that 'it's going to be
expensive' intake of air sound.

Is that prejudgement borne out in reality?

~~~
tyingq
$7 a month for the hobby plan doesn't seem that terrible.

But, serving static assets from Ruby seems heavy handed. You also end up
writing code for things other environments would handle with
configuration...like redirects, cache headers, and so forth.

Also, while $7 isn't a lot, it is a little more than other solutions in this
hobby level space.

The suggestions for Netlify and Firebase seem better ideas for static content,
and both allow for changing configuration instead of coding to satisfy the
normal things you do for static assets. Both appear to be free at this hobby
level as well.

~~~
kristianp
You can use Go with Heroku, with a buildpack [1]. There's a free plan, but it
doesn't include SSL.

[1] [https://github.com/heroku/heroku-buildpack-
go](https://github.com/heroku/heroku-buildpack-go)

~~~
tyingq
The free plan also "sleeps" after inactivity, right? I assume that means a
really long page load for the visitor that follows the inactivity? And, you're
still left implementing caching, redirects, etc, in a language (Go or Ruby) vs
configuration directives.

Just seems a poor option compared to other choices, at least for static
content.

------
type0
Often when I recommend GAE to someone the answer is: "but it's Google they are
known to abandon their services". That and also the fear of being locked into
Googles Cloud ecosystem pushes many potential customers away.

~~~
wsh91
GAE gives at least a year after deprecation before turning off a feature.
[https://cloud.google.com/appengine/docs/deprecations/](https://cloud.google.com/appengine/docs/deprecations/)

(I work on Google Cloud and on Datastore, which is built into App Engine. We
bend over backwards to support existing code.)

~~~
iamgopal
My seven year old website work without single line of code since, so I know
this is true.

