BuildRouter sets up the HTTP routes and middleware
()
| 160 | |
| 161 | // BuildRouter sets up the HTTP routes and middleware |
| 162 | func (i *Imgproxy) BuildRouter() (*server.Router, error) { |
| 163 | r, err := server.NewRouter(&i.config.Server, i.monitoring, i.errorReporter) |
| 164 | if err != nil { |
| 165 | return nil, err |
| 166 | } |
| 167 | |
| 168 | r.GET("/", i.handlers.Landing.Execute) |
| 169 | r.GET("", i.handlers.Landing.Execute) |
| 170 | |
| 171 | r.GET(faviconPath, r.NotFoundHandler).Silent() |
| 172 | r.GET(healthPath, i.handlers.Health.Execute).Silent() |
| 173 | r.GET(wellKnownPath, r.NotFoundHandler).Silent() |
| 174 | |
| 175 | if i.config.Server.HealthCheckPath != "" { |
| 176 | r.GET(i.config.Server.HealthCheckPath, i.handlers.Health.Execute).Silent() |
| 177 | } |
| 178 | |
| 179 | r.GET( |
| 180 | "/*", i.handlers.Processing.Execute, |
| 181 | r.WithSecret, r.WithCORS, r.WithPanic, r.WithReportError, r.WithMonitoring, |
| 182 | ) |
| 183 | |
| 184 | r.HEAD("/*", r.OkHandler, r.WithCORS) |
| 185 | r.OPTIONS("/*", r.OkHandler, r.WithCORS) |
| 186 | |
| 187 | return r, nil |
| 188 | } |
| 189 | |
| 190 | // StartServer runs the imgproxy server. This function blocks until the context is cancelled. |
| 191 | // If hasStarted is not nil, it will be notified with the server address once |