Caddyfile raw

   1  # moxielang.dev: the vanity import root for the Moxie toolchain.
   2  #
   3  # Three audiences, one address, and they need different answers:
   4  #
   5  #   * Go's module resolution (`go get`, `go list`) asks for ?go-get=1 and must
   6  #     receive a 200 with the go-import meta tag. A redirect here is a resolution
   7  #     failure.
   8  #   * git's HTTP transport asks for /info/refs?service=git-upload-pack, so it is
   9  #     sent to the repository's GIT endpoint with the path and query preserved -
  10  #     `git clone https://moxielang.dev` then works, because git follows a 301
  11  #     only when the target is still a git endpoint.
  12  #   * A browser wants a location: it gets a real 301 to the repository page, not
  13  #     a client-side meta refresh.
  14  #
  15  # TLS is Caddy's job (automatic, Let's Encrypt). DNS: an A/AAAA record for
  16  # moxielang.dev pointing at the host that runs this.
  17  {$VANITY_ADDR:moxielang.dev} {
  18  	encode zstd gzip
  19  
  20  	@goGet query go-get=1
  21  	handle @goGet {
  22  		root * {$VANITY_ROOT:./public}
  23  		rewrite * /index.html
  24  		file_server
  25  	}
  26  
  27  	# The smart-HTTP endpoints: the path AND the query have to survive, and the
  28  	# target has to be the .git URL github serves them from.
  29  	@gitSmart path */info/refs */git-upload-pack */git-receive-pack
  30  	handle @gitSmart {
  31  		redir https://github.com/moxie-language/toolchain.git{uri} 301
  32  	}
  33  
  34  	handle {
  35  		redir https://github.com/moxie-language/toolchain 301
  36  	}
  37  }
  38