Caddy your Serverless Functions

(image from Ryan De Hamer)

Use Caddy to bring your serverless functions under one "custom domain" roof, with automatic HTTPS.

Why host your own API gateway?

First a public service announcement:

Each of the major cloud providers have an API management service that works well with their functions-as-a-service product. You may prefer to use that instead of hosting your own server.

For my personal project I wanted to:

Configuring Caddy v2

Caddy is an open source web server that offers a streamlined configuration for automatic HTTPS (by handling the certificate renewal for you) and reverse proxying.

This configuration example shows how to hide beyond a custom domain and expose the function at {
  handle_path /add* {
    rewrite * /myCloudFunction{uri}
    reverse_proxy {
      header_up Host ""
  log {
    output file /logs/

Here are the highlights:

If you're currently using an older version of Caddy (v1)

Caddy v2 was released in May 2020 and I recently went through the exercise of upgrading my Caddy v1 configuration and ran into a couple of challenges:

For reference, here was my original configuration from Caddy v1's: {
  proxy /add
  errors /log/
  log / /log/ "{combined}" {
    rotate_size 100
    rotate_keep 10

Wrapping up

As an engineer, hosting your own server with open source technology is a great way to stay sharp and learn about what's happening behind-the-scenes.