API Gatway updated, now communicates with frontend

This commit is contained in:
gaz8860 Gary 2023-04-15 23:21:15 +01:00
parent 6ad23b3e14
commit 9353c55d1d
4 changed files with 44 additions and 39 deletions

View 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; }
}

View File

@ -4,7 +4,7 @@
@using System.Text.Json;
@inject IHttpService httpService
@* @if (data != null)
@if (data != null)
{
@foreach (var component in data) {
switch (component.Type) {
@ -27,16 +27,16 @@
}
}
} *@
}
<pre>@response.Text</pre>
@code {
private Component response;
private Component[] data;
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;
}
}

View File

@ -17,7 +17,7 @@
{
@foreach (var module in response){
<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
</NavLink>
</div>

View File

@ -31,7 +31,6 @@ type Module struct {
Container string `json:"Container"`
}
var Containers []Container
func homePage(w http.ResponseWriter, r *http.Request) {
@ -42,50 +41,46 @@ func getSchema(w http.ResponseWriter, r *http.Request){
vars := mux.Vars(r)
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()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal("Failed to print Body: %v", err)
}
fmt.Fprintf(w,string(body))
}
requestURL := fmt.Sprintf("http://%s:8080/schema", key)
resp, err := http.Get(requestURL)
if err != nil {
log.Fatal("Request to container failed: %v", err)
}
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){
vars := mux.Vars(r)
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()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal("Failed to print Body: %v", err)
}
fmt.Fprintf(w,string(body))
}
requestURL := fmt.Sprintf("http://%s:8080/stats", key)
resp, err := http.Get(requestURL)
if err != nil {
log.Fatal("Request to container failed: %v", err)
}
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)
}