()
| 101 | } |
| 102 | |
| 103 | func newHandler() (*handler, error) { |
| 104 | cl, err := app.Client() |
| 105 | if err != nil { |
| 106 | return nil, fmt.Errorf("could not initialize a client: %v", err) |
| 107 | } |
| 108 | h := &handler{ |
| 109 | sh: cl, |
| 110 | cl: cl, |
| 111 | uiFiles: uistatic.Files, |
| 112 | } |
| 113 | |
| 114 | config, err := appConfig() |
| 115 | if err != nil { |
| 116 | return nil, err |
| 117 | } |
| 118 | |
| 119 | // Serve files from source root when running devcam |
| 120 | if config.SourceRoot != "" { |
| 121 | logf("Using UI resources (HTML, JS, CSS) from disk, under %v", config.SourceRoot) |
| 122 | h.uiFiles = os.DirFS(config.SourceRoot) |
| 123 | } |
| 124 | |
| 125 | mux := http.NewServeMux() |
| 126 | mux.HandleFunc("/", h.handleRoot) |
| 127 | mux.HandleFunc("/ui/", h.handleUiFile) |
| 128 | mux.HandleFunc("/uploadurl", h.handleUploadURL) |
| 129 | mux.HandleFunc("/upload", h.handleUpload) |
| 130 | mux.HandleFunc("/resource/", h.handleResource) |
| 131 | mux.HandleFunc("/makedoc", h.handleMakedoc) |
| 132 | mux.HandleFunc("/doc/", h.handleDoc) |
| 133 | mux.HandleFunc("/changedoc", h.handleChangedoc) |
| 134 | mux.HandleFunc("/robots.txt", handleRobots) |
| 135 | h.mux = mux |
| 136 | |
| 137 | if err := h.disco(); err != nil { |
| 138 | return nil, err |
| 139 | } |
| 140 | |
| 141 | if config != nil { |
| 142 | h.httpsCert = config.HTTPSCert |
| 143 | h.httpsKey = config.HTTPSKey |
| 144 | } |
| 145 | var authConfig string |
| 146 | if config == nil || config.Auth == "" { |
| 147 | authConfig = "none" |
| 148 | } else { |
| 149 | authConfig = config.Auth |
| 150 | } |
| 151 | am, err := auth.FromConfig(authConfig) |
| 152 | if err != nil { |
| 153 | return nil, err |
| 154 | } |
| 155 | h.am = am |
| 156 | return h, nil |
| 157 | } |
| 158 | |
| 159 | func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
| 160 | if auth.AllowedWithAuth(h.am, r, auth.OpAll) { |
no test coverage detected