DEV Community

Eduardo Issao Ito
Eduardo Issao Ito

Posted on • Edited on

5 1

Caddy as a simple "api gateway" with SSL

What is Caddy

Caddy is an open source web server with automatic HTTPS.
We will use it to create a simple "api gateway".

https://caddyserver.com/

Preparing sample services

Start sample services

docker container run -d -p 5000:5000 proclaim/crp-app1
docker container run -d -p 8800:8800 proclaim/crp-app2

Test services


curl http://localhost:5000/api/member
curl http://localhost:8800/api/food

Configuring local caddy

mkdir ~/api-gateway
cd ~/api-gateway

Obtain machine information

hostname
ziba-Aspire-A515-51G.adzubla.net

hostname -I
192.168.59.50 

Create the SSL certificate for this machine

openssl req -nodes -new -x509 -keyout server.key -out server.cert \
-subj "/C=AU/ST=Some-State/L=City/O=Company Name/OU=Department/CN=ziba-Aspire-A515-51G.adzubla.net"

Create Caddyfile configuration

ziba-Aspire-A515-51G.adzubla.net {
    tls /etc/server.cert /etc/server.key
    proxy /api/member  192.168.59.50:5000
    proxy /api/food    192.168.59.50:8800
}

Start caddy server

docker run -d \
  -p 443:2015 \
  -v $HOME/api-gateway/Caddyfile:/etc/Caddyfile \
  -v $HOME/api-gateway/server.key:/etc/server.key \
  -v $HOME/api-gateway/server.cert:/etc/server.cert \
  abiosoft/caddy:1.0.3-no-stats

Test https services through caddy

curl -k https://ziba-aspire-a515-51g.adzubla.net/api/member
curl -k https://ziba-aspire-a515-51g.adzubla.net/api/food

Reference: https://medium.com/bumps-from-a-little-front-end-programmer/caddy-reverse-proxy-tutorial-faa2ce22a9c6

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more