1
0

subdomain.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package dynamicproxy
  2. import (
  3. "log"
  4. "net/url"
  5. "imuslab.com/zoraxy/mod/dynamicproxy/dpcore"
  6. )
  7. /*
  8. Add an URL intoa custom subdomain service
  9. */
  10. func (router *Router) AddSubdomainRoutingService(options *SubdOptions) error {
  11. domain := options.Domain
  12. if domain[len(domain)-1:] == "/" {
  13. domain = domain[:len(domain)-1]
  14. }
  15. webProxyEndpoint := domain
  16. if options.RequireTLS {
  17. webProxyEndpoint = "https://" + webProxyEndpoint
  18. } else {
  19. webProxyEndpoint = "http://" + webProxyEndpoint
  20. }
  21. //Create a new proxy agent for this root
  22. path, err := url.Parse(webProxyEndpoint)
  23. if err != nil {
  24. return err
  25. }
  26. proxy := dpcore.NewDynamicProxyCore(path, "", options.SkipCertValidations)
  27. router.SubdomainEndpoint.Store(options.MatchingDomain, &ProxyEndpoint{
  28. RootOrMatchingDomain: options.MatchingDomain,
  29. Domain: domain,
  30. RequireTLS: options.RequireTLS,
  31. Proxy: proxy,
  32. SkipCertValidations: options.SkipCertValidations,
  33. RequireBasicAuth: options.RequireBasicAuth,
  34. BasicAuthCredentials: options.BasicAuthCredentials,
  35. })
  36. log.Println("Adding Subdomain Rule: ", options.MatchingDomain+" to "+domain)
  37. return nil
  38. }