Deno Deploy is an excellent, performant and cost-effective service geared toward hosting Deno apps at the edge. It can easily host a folder of static HTML files, if you provide an index.ts to launch something like "oak" to serve them (example index.ts
below).
(It's important to note that it's still officially considered beta as of May 2023, and there have been some surprising periods of downtime over the past few months... just be sure to keep that in mind)
Hugo is a phenomenally fast-building and mature SSG, which can produce a folder of static files, but requires a build step like hugo --gc --minify --verbose --baseURL=$HUGOBASEURL --ignoreCache
to generate them.
Below is a yaml file you would place in your project's .github/workflows
folder. If you link your Deno Deploy project using Github Actions instead of specifying an index file, it will defer to what's in this. In this case, the Hugo files generated into public
are being served by file_server.ts
but I imagine you could use oak
or other servers. You can see the build step for hugo is a bit involved. Your build might be simpler, but I need this due to the way I post new content to this microblog.
The action is using denoland/deployctl
to deploy to Deno Deploy, and I wanted to have the action ping Slack at the end, and include the deployment url, to make it easy to just click that to share with a client. The id
in that step is critical, as you refer to it in the "Ping Slack" step, referencing via steps.deploy.outputs.url
.
The default entrypoint for deployctl
is a remote file:
entrypoint: https://deno.land/[email protected]/http/file_server.ts # wraps the static output files
This serves up the site just fine, but if you want security headers or a 404, one option is to use a local file as follows:
- copy and save the sample
index.ts
to your Hugo project'sstatic
folder. - in
deploy.yml
, set theentrypoint
fordeployctl
toindex.ts
instead of the URI.
It has the same effect of wrapping and serving the site's files, as well as injecting whatever headers you need and providing a very simple text-only 404.
We ride on the backs of giants. Thanks to:
- Andy Jiang @lambtron for the blog post about how to host Hugo on Deno Deploy
- Yusuke Tanaka @magurotuna in the
deployctl
repo for pointing me in the right direction on getting the deploy URL into Slack - Bruno Bernardino for the tip about cron in github actions
- @peaceiris and @briannice for their useful actions for building Hugo and pinging Slack
- Github, Deno Deploy and Hugo teams