API Gatway updated, now communicates with frontend
This commit is contained in:
parent
6ad23b3e14
commit
9353c55d1d
10
src/PanoptesFrontend/Pages/TestCard.razor
Normal file
10
src/PanoptesFrontend/Pages/TestCard.razor
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<p>@Data.Text</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
[Parameter]
|
||||||
|
public Component Data { get; set; }
|
||||||
|
}
|
||||||
@ -4,7 +4,7 @@
|
|||||||
@using System.Text.Json;
|
@using System.Text.Json;
|
||||||
@inject IHttpService httpService
|
@inject IHttpService httpService
|
||||||
|
|
||||||
@* @if (data != null)
|
@if (data != null)
|
||||||
{
|
{
|
||||||
@foreach (var component in data) {
|
@foreach (var component in data) {
|
||||||
switch (component.Type) {
|
switch (component.Type) {
|
||||||
@ -27,16 +27,16 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} *@
|
}
|
||||||
|
|
||||||
<pre>@response.Text</pre>
|
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
private Component response;
|
private Component[] data;
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
response = await httpService.GetAsync<Component>("http://localhost:8080/test");
|
var response = await httpService.GetAsync<Schema>("http://localhost:10000/localhost/schema");
|
||||||
|
data = response.components;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
{
|
{
|
||||||
@foreach (var module in response){
|
@foreach (var module in response){
|
||||||
<div class="nav-item px-3">
|
<div class="nav-item px-3">
|
||||||
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
|
<NavLink class="nav-link" href=@module.Name Match="NavLinkMatch.All">
|
||||||
<span class="oi oi-home" aria-hidden="true"></span> @module.Name
|
<span class="oi oi-home" aria-hidden="true"></span> @module.Name
|
||||||
</NavLink>
|
</NavLink>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -31,7 +31,6 @@ type Module struct {
|
|||||||
Container string `json:"Container"`
|
Container string `json:"Container"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var Containers []Container
|
|
||||||
|
|
||||||
|
|
||||||
func homePage(w http.ResponseWriter, r *http.Request) {
|
func homePage(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -42,50 +41,46 @@ func getSchema(w http.ResponseWriter, r *http.Request){
|
|||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
key := vars["container"]
|
key := vars["container"]
|
||||||
|
|
||||||
for _, container := range Containers {
|
|
||||||
if container.Id == key {
|
|
||||||
requestURL := fmt.Sprintf("http://%s:%s/schema", container.Name, container.port)
|
|
||||||
resp, err := http.Get(requestURL)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Request to container failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer resp.Body.Close()
|
requestURL := fmt.Sprintf("http://%s:8080/schema", key)
|
||||||
|
resp, err := http.Get(requestURL)
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
if err != nil {
|
||||||
if err != nil {
|
log.Fatal("Request to container failed: %v", err)
|
||||||
log.Fatal("Failed to print Body: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Fprintf(w,string(body))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Failed to print Body: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.WriteHeader(resp.StatusCode)
|
||||||
|
w.Write(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getStats(w http.ResponseWriter, r *http.Request){
|
func getStats(w http.ResponseWriter, r *http.Request){
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
key := vars["container"]
|
key := vars["container"]
|
||||||
|
|
||||||
for _, container := range Containers {
|
|
||||||
if container.Id == key {
|
|
||||||
requestURL := fmt.Sprintf("http://%s:%s/stats", container.Name, container.port)
|
|
||||||
resp, err := http.Get(requestURL)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Request to container failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer resp.Body.Close()
|
requestURL := fmt.Sprintf("http://%s:8080/stats", key)
|
||||||
|
resp, err := http.Get(requestURL)
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
if err != nil {
|
||||||
if err != nil {
|
log.Fatal("Request to container failed: %v", err)
|
||||||
log.Fatal("Failed to print Body: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Fprintf(w,string(body))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Failed to print Body: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.WriteHeader(resp.StatusCode)
|
||||||
|
w.Write(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user