forked from kubeflow/model-registry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bff): serving static assets on bff (kubeflow#690)
* feat(bff): serving static assets on bff Signed-off-by: Eder Ignatowicz <[email protected]> * Update clients/ui/bff/Dockerfile Co-authored-by: Griffin Sullivan <[email protected]> Signed-off-by: Eder Ignatowicz <[email protected]> --------- Signed-off-by: Eder Ignatowicz <[email protected]> Co-authored-by: Griffin Sullivan <[email protected]>
- Loading branch information
1 parent
eb21a6d
commit 4cedb36
Showing
10 changed files
with
176 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package api | ||
|
||
import ( | ||
"github.com/kubeflow/model-registry/ui/bff/internal/config" | ||
"github.com/kubeflow/model-registry/ui/bff/internal/repositories" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"io" | ||
"net/http" | ||
httptest "net/http/httptest" | ||
) | ||
|
||
var _ = Describe("Static File serving Test", func() { | ||
var ( | ||
server *httptest.Server | ||
client *http.Client | ||
) | ||
|
||
Context("serving static files at /", Ordered, func() { | ||
|
||
BeforeAll(func() { | ||
envConfig := config.EnvConfig{ | ||
StaticAssetsDir: resolveStaticAssetsDirOnTests(), | ||
} | ||
app := &App{ | ||
kubernetesClient: k8sClient, | ||
repositories: repositories.NewRepositories(mockMRClient), | ||
logger: logger, | ||
config: envConfig, | ||
} | ||
|
||
server = httptest.NewServer(app.Routes()) | ||
client = server.Client() | ||
}) | ||
|
||
AfterAll(func() { | ||
server.Close() | ||
}) | ||
|
||
It("should serve index.html from the root path", func() { | ||
resp, err := client.Get(server.URL + "/") | ||
Expect(err).NotTo(HaveOccurred()) | ||
defer resp.Body.Close() | ||
|
||
Expect(resp.StatusCode).To(Equal(http.StatusOK)) | ||
|
||
body, err := io.ReadAll(resp.Body) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(string(body)).To(ContainSubstring("BFF Stub Page")) | ||
}) | ||
|
||
It("should serve subfolders from the root path", func() { | ||
resp, err := client.Get(server.URL + "/sub/test.html") | ||
Expect(err).NotTo(HaveOccurred()) | ||
defer resp.Body.Close() | ||
|
||
Expect(resp.StatusCode).To(Equal(http.StatusOK)) | ||
|
||
body, err := io.ReadAll(resp.Body) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(string(body)).To(ContainSubstring("BFF Stub Subfolder Page")) | ||
}) | ||
|
||
It("should return 404 for a non-existent static file", func() { | ||
resp, err := client.Get(server.URL + "/non-existent.html") | ||
Expect(err).NotTo(HaveOccurred()) | ||
defer resp.Body.Close() | ||
|
||
Expect(resp.StatusCode).To(Equal(http.StatusNotFound)) | ||
}) | ||
|
||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
package config | ||
|
||
type EnvConfig struct { | ||
Port int | ||
MockK8Client bool | ||
MockMRClient bool | ||
DevMode bool | ||
StandaloneMode bool | ||
DevModePort int | ||
Port int | ||
MockK8Client bool | ||
MockMRClient bool | ||
DevMode bool | ||
StandaloneMode bool | ||
DevModePort int | ||
StaticAssetsDir string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>BFF Stub Page</title> | ||
</head> | ||
<body> | ||
<h1>Welcome to the BFF Stub Page</h1> | ||
<p>This is a placeholder page for the serving frontend.</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>BFF Stub Subfolder Page</title> | ||
</head> | ||
<body> | ||
<h1>Welcome to the BFF Stub Subfolder Page</h1> | ||
<p>This is a placeholder page for the serving frontend.</p> | ||
</body> | ||
</html> |