Use App Engine and Go to Host a Static Website with Same Domain Redirects(thornelabs.net)
thornelabs.net
Use App Engine and Go to Host a Static Website with Same Domain Redirects
https://thornelabs.net/2017/03/08/use-google-app-engine-and-golang-to-host-a-static-website-with-same-domain-redirects.html
25 comments
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.
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.
Might be nice to add that bit in. Better performance for visitors, and would keep you in the free tier longer if traffic grows.
You are correct, and great points. This is my first Golang app, so doing what you suggested is my next step. Thanks!
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.Or just use Netlify: https://www.netlify.com/
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.
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/us...
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.
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.
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.
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)
app engine static files are dispatched by google cdn network for free. CloudFront is not free.
I think the OP is subverting the CDN functionality since the static assets are flowing through the golang code.
I prefer Heroku over google cloud, better documentation and deploying is really easy.
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?
Is that prejudgement borne out in reality?
$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.
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.
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
[1] https://github.com/heroku/heroku-buildpack-go
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.
Just seems a poor option compared to other choices, at least for static content.
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.
GAE gives at least a year after deprecation before turning off a feature. 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.)
(I work on Google Cloud and on Datastore, which is built into App Engine. We bend over backwards to support existing code.)
My seven year old website work without single line of code since, so I know this is true.
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/
[1] https://www.josharcher.uk