Caddy 2 server the silver bullet of serving

Caddy 2 server the silver bullet of serving

First and foremost this post is about a Go-lang server; wait it will be in a node.js context!

Node.js is beautiful and brilliant. It takes a mature developer to admit where something shines and where it could use some help. With every language, or library the authors make some choices on where it should it shine and what can lag.

I won't drill down into the nitty gritty but where I think node can use a friend like Caddy are things like serving binary files, rate limiting access to the server, creating an HTTP/2 or /3 server. (node recently made HTTP/2 a first class citizen but you still need to setup a Let's encrypt certificate)

HTTP/2 really shines with serving static assets, in the past with HTTP/1 we used CDN's to maximize parallel requests and dns lookups. Nowadays you can create many requests with only one DNS lookup and all the assets over the same wire.

I've been using Caddy since the early v1 days, there are a few feature I miss that haven't landed in v2 yet; such as protecting routes with JWT via a plugin. Overall if you are creating a new project you should use V2.

Getting started! You can download the binary here or use the handy DigitalOcean droplet

For me a common use case of Caddy is as a static file server and a reverse proxy for my backend services. Here's what works for me as "Caddyfile" the yaml edition of the configuration file

example.com {
encode gzip
header Cache-Control max-age=31536000
file_server {
root /var/www/html
}
log {
output file /var/log/access.log
}

}

api.example.com {
reverse_proxy 127.0.0.1:3000
}

And just like that you are likely to get 100 lighthouse score on google served over http/2.

Here's more information about Caddy, hope this helps!

Comments and retweets welcome twitter.com/cactusanddove/status/1274861623..

Sandeep Panda's photo

Big fan of Caddy! We have been using it at Hashnode to serve SSL certs on demand. I wrote about it here: engineering.hashnode.com/after-4-years-with..

Greg Benner's photo

It's really an amazing reverse-proxy! Instant google performance score 100

Emil Moe's photo

I was looking into Caddy to realize that it's not free for commercial projects, so I turned it down for that reason.

Show +1 replies
Sandeep Panda's photo

Greg Benner, Emil Moe I think with Caddy 2 even that requirement is also removed.

github.com/caddyserver/caddy/issues/2786

Emil Moe's photo

Sandeep Panda It's not even half a year ago I saw somewhere that it costs money, I think it was on their website, but I can't tell now unfortunately. But good choice if they choose to make it free like their competitors, although their past prevented me from choosing their software and now it's all set up.