Merge pull request #47 from ldez/feature/api-frontend-routes
feat(api): add api routes for Frontend Routes
This commit is contained in:
commit
f89b727ad1
3 changed files with 64 additions and 132 deletions
|
@ -321,14 +321,16 @@ $ curl -s "http://localhost:8080/api" | jq .
|
|||
}
|
||||
```
|
||||
|
||||
* `/api/providers`: `GET` providers
|
||||
* `/api/providers/{provider}`: `GET` or `PUT` provider
|
||||
* `/api/providers/{provider}/backends`: `GET` backends
|
||||
* `/api/providers/{provider}/backends/{backend}`: `GET` a backend
|
||||
* `/api/providers/{provider}/backends/{backend}/servers`: `GET` servers in a backend
|
||||
* `/api/providers/{provider}/backends/{backend}/servers/{server}`: `GET` a server in a backend
|
||||
* `/api/providers/{provider}/frontends`: `GET` frontends
|
||||
* `/api/providers/{provider}/frontends/{frontend}`: `GET` a frontend
|
||||
- `/api/providers`: `GET` providers
|
||||
- `/api/providers/{provider}`: `GET` or `PUT` provider
|
||||
- `/api/providers/{provider}/backends`: `GET` backends
|
||||
- `/api/providers/{provider}/backends/{backend}`: `GET` a backend
|
||||
- `/api/providers/{provider}/backends/{backend}/servers`: `GET` servers in a backend
|
||||
- `/api/providers/{provider}/backends/{backend}/servers/{server}`: `GET` a server in a backend
|
||||
- `/api/providers/{provider}/frontends`: `GET` frontends
|
||||
- `/api/providers/{provider}/frontends/{frontend}`: `GET` a frontend
|
||||
- `/api/providers/{provider}/frontends/{frontend}/routes`: `GET` routes in a frontend
|
||||
- `/api/providers/{provider}/frontends/{frontend}/routes/{route}`: `GET` a route in a frontend
|
||||
|
||||
|
||||
## <a id="docker"></a> Docker backend
|
||||
|
|
|
@ -1,101 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>/ˈTræfɪk/</title>
|
||||
|
||||
<!-- Bootstrap -->
|
||||
<link rel="stylesheet" href="/static/bootstrap/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="/static/bootstrap/css/bootstrap-theme.min.css">
|
||||
<script src="/static/jquery-2.1.4.min.js"></script>
|
||||
<script src="/static/bootstrap/js/bootstrap.min.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
body {padding-bottom: 70px;}
|
||||
.content {margin:10px;}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
<div class="jumbotron">
|
||||
<h1>/ˈTræfɪk/</h1>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
|
||||
<div class="col-md-6">
|
||||
<!-- <div class="panel-heading">Frontends</div>
|
||||
<div class="panel-body"> -->
|
||||
{{range $keyProviders, $valueProviders := .Configurations}}
|
||||
{{range $keyFrontends, $valueFrontends := $valueProviders.Frontends}}
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">{{$keyFrontends}} - ({{$keyProviders}})</div>
|
||||
<div class="panel-body">
|
||||
<a class="btn btn-info" role="button" data-toggle="collapse" href="#{{$valueFrontends.Backend}}" aria-expanded="false">
|
||||
{{$valueFrontends.Backend}}
|
||||
</a>
|
||||
</div>
|
||||
<table class="table table-striped table-hover">
|
||||
<tr>
|
||||
<td><em>Route</em></td>
|
||||
<td><em>Rule</em></td>
|
||||
<td><em>Value</em></td>
|
||||
</tr>
|
||||
{{range $keyRoutes, $valueRoutes := $valueFrontends.Routes}}
|
||||
<tr>
|
||||
<td>{{$keyRoutes}}</td>
|
||||
<td>{{$valueRoutes.Rule}}</td>
|
||||
<td>{{$valueRoutes.Value}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</table>
|
||||
</div>
|
||||
{{end}}
|
||||
{{end}}
|
||||
<!-- </div> -->
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<!-- <div class="panel-heading">Backends</div>
|
||||
<div class="panel-body"> -->
|
||||
{{range $keyProviders, $valueProviders := .Configurations}}
|
||||
{{range $keyBackends, $valueBackends := $valueProviders.Backends}}
|
||||
<div class="panel panel-primary" id="{{$keyBackends}}">
|
||||
<div class="panel-heading">{{$keyBackends}} - ({{$keyProviders}})</div>
|
||||
<div class="panel-body">
|
||||
{{with $valueBackends.LoadBalancer}}
|
||||
<a class="btn btn-info" role="button">
|
||||
Load Balancer: {{.Method}}
|
||||
</a>
|
||||
{{end}}
|
||||
{{with $valueBackends.CircuitBreaker}}
|
||||
<a class="btn btn-info" role="button">
|
||||
Circuit Breaker: {{.Expression}}
|
||||
</a>
|
||||
{{end}}
|
||||
</div>
|
||||
<table class="table table-striped table-hover">
|
||||
<tr>
|
||||
<td><em>Server</em></td>
|
||||
<td><em>URL</em></td>
|
||||
<td><em>Weight</em></td>
|
||||
</tr>
|
||||
{{range $keyServers, $valueServers := $valueBackends.Servers}}
|
||||
<tr>
|
||||
<td>{{$keyServers}}</td>
|
||||
<td><code><A href="{{$valueServers.URL}}">{{$valueServers.URL}}</A></code></td>
|
||||
<td>{{$valueServers.Weight}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</table>
|
||||
</div>
|
||||
{{end}}
|
||||
{{end}}
|
||||
<!-- </div> -->
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
77
web.go
77
web.go
|
@ -51,6 +51,8 @@ func (provider *WebProvider) Provide(configurationChan chan<- configMessage) err
|
|||
systemRouter.Methods("GET").Path("/api/providers/{provider}/backends/{backend}/servers/{server}").HandlerFunc(getServerHandler)
|
||||
systemRouter.Methods("GET").Path("/api/providers/{provider}/frontends").HandlerFunc(getFrontendsHandler)
|
||||
systemRouter.Methods("GET").Path("/api/providers/{provider}/frontends/{frontend}").HandlerFunc(getFrontendHandler)
|
||||
systemRouter.Methods("GET").Path("/api/providers/{provider}/frontends/{frontend}/routes").HandlerFunc(getRoutesHandler)
|
||||
systemRouter.Methods("GET").Path("/api/providers/{provider}/frontends/{frontend}/routes/{route}").HandlerFunc(getRouteHandler)
|
||||
|
||||
// Expose dashboard
|
||||
systemRouter.Methods("GET").Path("/").HandlerFunc(func(response http.ResponseWriter, request *http.Request) {
|
||||
|
@ -115,29 +117,6 @@ func getBackendHandler(response http.ResponseWriter, request *http.Request) {
|
|||
http.NotFound(response, request)
|
||||
}
|
||||
|
||||
func getFrontendsHandler(response http.ResponseWriter, request *http.Request) {
|
||||
vars := mux.Vars(request)
|
||||
providerID := vars["provider"]
|
||||
if provider, ok := currentConfigurations[providerID]; ok {
|
||||
templatesRenderer.JSON(response, http.StatusOK, provider.Frontends)
|
||||
} else {
|
||||
http.NotFound(response, request)
|
||||
}
|
||||
}
|
||||
|
||||
func getFrontendHandler(response http.ResponseWriter, request *http.Request) {
|
||||
vars := mux.Vars(request)
|
||||
providerID := vars["provider"]
|
||||
frontendID := vars["frontend"]
|
||||
if provider, ok := currentConfigurations[providerID]; ok {
|
||||
if frontend, ok := provider.Frontends[frontendID]; ok {
|
||||
templatesRenderer.JSON(response, http.StatusOK, frontend)
|
||||
return
|
||||
}
|
||||
}
|
||||
http.NotFound(response, request)
|
||||
}
|
||||
|
||||
func getServersHandler(response http.ResponseWriter, request *http.Request) {
|
||||
vars := mux.Vars(request)
|
||||
providerID := vars["provider"]
|
||||
|
@ -166,3 +145,55 @@ func getServerHandler(response http.ResponseWriter, request *http.Request) {
|
|||
}
|
||||
http.NotFound(response, request)
|
||||
}
|
||||
|
||||
func getFrontendsHandler(response http.ResponseWriter, request *http.Request) {
|
||||
vars := mux.Vars(request)
|
||||
providerID := vars["provider"]
|
||||
if provider, ok := currentConfigurations[providerID]; ok {
|
||||
templatesRenderer.JSON(response, http.StatusOK, provider.Frontends)
|
||||
} else {
|
||||
http.NotFound(response, request)
|
||||
}
|
||||
}
|
||||
|
||||
func getFrontendHandler(response http.ResponseWriter, request *http.Request) {
|
||||
vars := mux.Vars(request)
|
||||
providerID := vars["provider"]
|
||||
frontendID := vars["frontend"]
|
||||
if provider, ok := currentConfigurations[providerID]; ok {
|
||||
if frontend, ok := provider.Frontends[frontendID]; ok {
|
||||
templatesRenderer.JSON(response, http.StatusOK, frontend)
|
||||
return
|
||||
}
|
||||
}
|
||||
http.NotFound(response, request)
|
||||
}
|
||||
|
||||
func getRoutesHandler(response http.ResponseWriter, request *http.Request) {
|
||||
vars := mux.Vars(request)
|
||||
providerID := vars["provider"]
|
||||
frontendID := vars["frontend"]
|
||||
if provider, ok := currentConfigurations[providerID]; ok {
|
||||
if frontend, ok := provider.Frontends[frontendID]; ok {
|
||||
templatesRenderer.JSON(response, http.StatusOK, frontend.Routes)
|
||||
return
|
||||
}
|
||||
}
|
||||
http.NotFound(response, request)
|
||||
}
|
||||
|
||||
func getRouteHandler(response http.ResponseWriter, request *http.Request) {
|
||||
vars := mux.Vars(request)
|
||||
providerID := vars["provider"]
|
||||
frontendID := vars["frontend"]
|
||||
routeID := vars["route"]
|
||||
if provider, ok := currentConfigurations[providerID]; ok {
|
||||
if frontend, ok := provider.Frontends[frontendID]; ok {
|
||||
if route, ok := frontend.Routes[routeID]; ok {
|
||||
templatesRenderer.JSON(response, http.StatusOK, route)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
http.NotFound(response, request)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue