1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package main
- import (
- "fmt"
- "io/ioutil"
- "log"
- "net/http"
- "regexp"
- "imuslab.com/zoraxy/mod/acme"
- "imuslab.com/zoraxy/mod/dynamicproxy"
- )
- /*
- acme.go
- This script handle special routing required for acme auto cert renew functions
- */
- func acmeRegisterSpecialRoutingRule() {
- a := acme.NewACME("[email protected]", []string{"r5desktop.alanyeung.co"})
- err := dynamicProxyRouter.AddRoutingRules(&dynamicproxy.RoutingRule{
- ID: "acme-autorenew",
- MatchRule: func(r *http.Request) bool {
- found, _ := regexp.MatchString("/.well-known/*", r.RequestURI)
- /*
- if r.RequestURI == "/.well-known/" {
- return true
- }
- return false
- */
- return found
- },
- RoutingHandler: func(w http.ResponseWriter, r *http.Request) {
- req, err := http.NewRequest(http.MethodGet, "http://localhost:5002"+r.RequestURI, nil)
- req.Host = "r5desktop.alanyeung.co"
- if err != nil {
- fmt.Printf("client: could not create request: %s\n", err)
- }
- res, err := http.DefaultClient.Do(req)
- if err != nil {
- fmt.Printf("client: error making http request: %s\n", err)
- }
- resBody, err := ioutil.ReadAll(res.Body)
- if err != nil {
- fmt.Printf("error reading: %s\n", err)
- }
- w.Write(resBody)
- //w.Write([]byte("HELLO WORLD, THIS IS ACME REQUEST HANDLER"))
- },
- Enabled: true,
- })
- if err != nil {
- log.Println("[Err] " + err.Error())
- }
- a.ObtainCert()
- }
|