Skip to main content

Command Palette

Search for a command to run...

Caddy 2 server the silver bullet of serving

Published
2 min read
Caddy 2 server the silver bullet of serving
G

OpenFaas, Docker Swarm, Mobx, Vue js 2, Vuex, React, Angular 1, ES6, TDD, Jasmine, BDD, Mongo, Node, Koa, Scrum, Sprints, Unit Tests, Isomorphic (Universal) JavaScript, lo-dash, pair programming, graphql, REST api, SASS, BEM, HTML5, rethinkdb, mongodb, CI tools, AWS Lambda, AWS S3.

Specialist in performance oriented javascript architecture for web, mobile, client and server side. Passionate about realtime web.

Enjoy mentoring and pairing with other developers to share knowledge. Enjoy testing code and getting good coverage, focused on results driven agile coding.

Extremely active in the javascript community, run two fullstack javascript meetups and keep in touch with various library / framework / book authors.

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 https://twitter.com/cactusanddove/status/1274861623094763531?s=20

94 views
E
Emil Moe5y ago

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

G

Caddy is actually free and open source, caveat is you use the installer you should pay for commercial. If you build Caddy without the installer it's free :)

S

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

https://github.com/caddyserver/caddy/issues/2786

1
E
Emil Moe5y ago

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.

1
S

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

1
G

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