diff --git a/src/backend/cmd/main.go b/src/backend/cmd/main.go index f989b57..79428f6 100644 --- a/src/backend/cmd/main.go +++ b/src/backend/cmd/main.go @@ -66,13 +66,14 @@ func getSchema(c echo.Context) error { log.Fatalf("Failed to print Body: %v", err) } - return c.JSONBlob(http.StatusOK, body) + return c.JSONBlob(resp.StatusCode, body) } -func getStats(c echo.Context) error { - key := c.Param("container") +func getComponent(c echo.Context) error { + container := c.Param("container") + component := c.Param("component") - requestURL := fmt.Sprintf("http://%s:8080", key) + requestURL := fmt.Sprintf("http://%s:8080/component/%s", container, component) resp, err := http.Get(requestURL) if err != nil { log.Fatalf("Request to container failed: %v", err) @@ -88,6 +89,25 @@ func getStats(c echo.Context) error { return c.JSONBlob(http.StatusOK, body) } +func postComponent(c echo.Context) error { + container := c.Param("container") + component := c.Param("component") + + requestURL := fmt.Sprintf("http://%s:8080/component/%s", container, component) + resp, err := http.Post(requestURL, "application/json", c.Request().Body) + if err != nil { + log.Fatalf("Request to container failed: %v", err) + } + + defer resp.Body.Close() + + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + log.Fatalf("Failed to print Body: %v", err) + } + + return c.JSONBlob(http.StatusOK, body) +} func GetModules(db *sql.DB) echo.HandlerFunc { return func(c echo.Context) error { @@ -226,7 +246,8 @@ func main() { e := echo.New() e.GET("/", homePage) e.GET("/:container/schema", getSchema) - e.GET("/:container/stats", getStats) + e.GET("/component/:container/:component", getComponent) + e.POST("/component/:container/:component", postComponent) e.GET("/modules", GetModules(db)) e.POST("/user/register", RegisterUser(db)) e.POST("/user/login", LoginUser(db, jwtSecret))