Caddy Newbie Questions

Hi Caddy community,

Thanks for the active Caddy project. I asked a question on the golang nuts mailing list two days back for a problem and was recommended Caddy as a solution by someone there. I would like to explain my need and better understand if Caddy will be a good solution for me. I will be thankful if any of you can read through and explain if I will be in the right direction with Caddy.

I have written a bunch of HTTP handlers. As of now, I have written a main program that uses all the Handlers in a HTTP mux, for different paths and deploy these handlers as a single Go binary. All these handlers talk REST and also does CORS handling (has code like below):

res.Header().Set(“Access-Control-Allow-Origin”, conf.CORS_ORIGIN)
res.Header().Set(“Access-Control-Allow-Methods”, “POST,OPTIONS”)
res.Header().Set(“Access-Control-Allow-Headers”, “Authorization”)
res.Header().Set(“Access-Control-Allow-Credentials”, “true”)

One of the HTTP handlers is a login handler which will take an username and password and will give out a JWT. This JWT will be used for authentication in the further handlers. I have written a React webapp that will talk to this monolithic Golang server.

I have purchased a domain name too (let us call it example.com for now). Now, I want to deploy the Golang server under: https://api.example.com and the react webapp under https://www.example.com

Even though the Golang server is monolithic as of now, in future, I may be splitting the handlers into their own binaries and then launch multiple processes. Also, I may want to use something like Kubernetes in future, to scale these individual services differently (like only one node for the login service whereas the core-search service may need at least 4 nodes, etc.).

As I have mentioned the current state of the project and the future direction, I would like to seek your opinion on, if Caddy would be a good tool for me to use here. My only constraints are:

  1. HTTPS Enforcement (Potentially by talking to letsencrypt)
  2. Ability to work with kubernetes (In future)

Are there any good tutorials or talks or videos or blogposts where this process (Deploying a Golang HTTP server via caddy on the web, with certificates from letsencrypt) is explained / taught ? I did try Googling and searching in youtube before asking here, but could not find much resources. Any help on this will be appreciated. Thanks.

I gave a talk at dotGo last year about using the ACME protocol in your Go programs, maybe you’ll find it helpful: dotGo 2016 - Matthew Holt - Go with ACME - YouTube

But if you want to use Caddy, you can use it as a reverse proxy into your web application and then Caddy can take care of the Let’s Encrypt work for you. Either way should work fine for what you need. (And yes, there are ways to use LE with Kubernetes effectively either way.)

Hi Matt,

Thanks for the talk. It was nice. I can’t say I fully understand everything but at least I got a good overall picture.

Using Caddy in front of my HTTP server seems to be straight-forward (based on your video) but I am a little confused as to how the https redirection will happen, if I should edit/remove the CORS handling or JWT handling in my code, etc. as the caddy homepage mentions about a CORS and JWT middleware too. I will dig further for other tutorials and may be play around a little and get my hands dirty to understand better.

If possible, I would request you to give a screencast/talk in future, for an usecase of someone having a simple API server in Golang (with 2 handlers, a login handler (that returns a JWT), a GET /posts or some such handler) a simple react front-end in front of that, and how to deploy that via Caddy so that in future, if the backend has to be kubernetized etc. it will be useful. I would be more than happy to provide you with a simple API and a web gui sources if needed. Thanks.

Clients should be taking care of obeying the redirect properly, if the server issues a 301.

Ha! :wink: That’s really, really, really specific. And I don’t know React. Sounds like it would make an interesting blog post though.

Ah okay.[quote=“matt, post:4, topic:1596”]
Ha! :wink: That’s really, really, really specific. And I don’t know React. Sounds like it would make an interesting blog post though.
[/quote]

Sure :slight_smile: It is past midnight for me now. I will try to send you such a source sometime next week and may be we could build a blog post / tutorial from that. Thanks.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.