-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/omec-project/webconsole i…
…nto add-swagger-ui Signed-off-by: Patricia Reinoso <[email protected]>
- Loading branch information
Showing
10 changed files
with
118 additions
and
8 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,16 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2024 Canonical Ltd. | ||
|
||
//go:build !ui | ||
|
||
package webui_service | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"github.com/omec-project/webconsole/backend/logger" | ||
) | ||
|
||
func AddUiService(engine *gin.Engine) *gin.RouterGroup { | ||
logger.WebUILog.Infoln("UI service will not be added") | ||
return nil | ||
} |
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,42 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2024 Canonical Ltd. | ||
|
||
// +build ui | ||
|
||
package webui_service | ||
|
||
import ( | ||
"io/fs" | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/omec-project/webconsole/backend/logger" | ||
"github.com/omec-project/webconsole/ui" | ||
) | ||
|
||
func AddUiService(engine *gin.Engine) { | ||
logger.WebUILog.Infoln("Adding UI service") | ||
staticFilesSystem, err := fs.Sub(ui.FrontendFS, "frontend_files") | ||
if err != nil { | ||
logger.WebUILog.Fatal(err) | ||
} | ||
|
||
engine.Use(func(c *gin.Context) { | ||
if !isApiUrlPath(c.Request.URL.Path){ | ||
htmlPath := strings.TrimPrefix(c.Request.URL.Path, "/") + ".html" | ||
if _, err := staticFilesSystem.Open(htmlPath); err == nil { | ||
c.Request.URL.Path = htmlPath | ||
} | ||
fileServer := http.FileServer(http.FS(staticFilesSystem)) | ||
fileServer.ServeHTTP(c.Writer, c.Request) | ||
c.Abort() | ||
} | ||
}) | ||
} | ||
|
||
func isApiUrlPath(path string) bool{ | ||
return strings.HasPrefix(path, "/config/v1/") || strings.HasPrefix(path, "/api/"); | ||
} | ||
|
||
|
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,13 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2024 Canonical Ltd. | ||
|
||
// +build ui | ||
|
||
package ui | ||
|
||
import ( | ||
"embed" | ||
) | ||
|
||
//go:embed all:frontend_files | ||
var FrontendFS embed.FS |
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,14 @@ | ||
<!-- SPDX-License-Identifier: Apache-2.0 --> | ||
<!-- Copyright 2024 Canonical Ltd. --> | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Webui</title> | ||
</head> | ||
<body> | ||
<h1>Welcome to the webconsole UI</h1> | ||
<h3>This is an example of a static file from a frontend application.</h3> | ||
</body> | ||
</html> |