Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add static files support for ui #143

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions backend/webui_service/serve_static_files.go
gruyaume marked this conversation as resolved.
Show resolved Hide resolved
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 4 Canonical Ltd.

//go:build !ui
// +build !ui

package webui_service

import "github.com/gin-gonic/gin"

func (*WEBUI) SetUpStaticFiles(router *gin.Engine) {}
21 changes: 21 additions & 0 deletions backend/webui_service/serve_static_files_with_frontend.go
gruyaume marked this conversation as resolved.
Show resolved Hide resolved
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2024 Canonical Ltd.

//go:build ui
// +build ui

package webui_service

import (
"embed"
"net/http"

"github.com/gin-gonic/gin"
)

//go:embed webui/frontend/dist/*
var staticFiles embed.FS

func (*WEBUI) SetUpStaticFiles(router *gin.Engine) {
router.StaticFS("/static", http.FS(staticFiles))
}
5 changes: 3 additions & 2 deletions backend/webui_service/webui_init.go
Expand Up @@ -10,13 +10,14 @@ package webui_service
import (
"bufio"
"fmt"
"github.com/omec-project/webconsole/dbadapter"
"net/http"
"os/exec"
"strconv"
"sync"
"time"

"github.com/omec-project/webconsole/dbadapter"

"github.com/gin-contrib/cors"
"github.com/omec-project/http2_util"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -187,7 +188,7 @@ func (webui *WEBUI) Start() {
AllowAllOrigins: true,
MaxAge: 86400,
}))

webui.SetUpStaticFiles(subconfig_router)
go func() {
httpAddr := ":" + strconv.Itoa(factory.WebUIConfig.Configuration.CfgPort)
initLog.Infoln("Webui HTTP addr:", httpAddr, factory.WebUIConfig.Configuration.CfgPort)
Expand Down