satellite/console: optionally serve vuetify POC from satellite

This change slightly modifies the logic for serving the vuetify
frontend. After this change, if the config `console.use-vuetify-project`
is set to `true`, the Vuetify UI will be served at the `/vuetifypoc`
prefix. The POC is only project dashboard right now; the existing
login/registration pages must be used, but once the cookie is set, the
POC will work correctly.

Change-Id: I7725f23a0d2b04f274bab36d8be3370116687d1b
This commit is contained in:
Moby von Briesen 2023-06-08 17:53:24 -04:00 committed by Storj Robot
parent edbea5efe1
commit 3bc300ef55
2 changed files with 41 additions and 10 deletions

View File

@ -363,6 +363,9 @@ func NewServer(logger *zap.Logger, config Config, service *console.Service, oidc
slashRouter.HandleFunc("/activation", server.accountActivationHandler)
slashRouter.HandleFunc("/cancel-password-recovery", server.cancelPasswordRecoveryHandler)
if server.config.UseVuetifyProject {
router.PathPrefix("/vuetifypoc").Handler(http.HandlerFunc(server.vuetifyAppHandler))
}
router.PathPrefix("/").Handler(http.HandlerFunc(server.appHandler))
}
@ -415,8 +418,8 @@ func (server *Server) Close() error {
return server.server.Close()
}
// appHandler is web app http handler function.
func (server *Server) appHandler(w http.ResponseWriter, r *http.Request) {
// setAppHeaders sets the necessary headers for requests to the app.
func (server *Server) setAppHeaders(w http.ResponseWriter, r *http.Request) {
header := w.Header()
if server.config.CSPEnabled {
@ -438,14 +441,13 @@ func (server *Server) appHandler(w http.ResponseWriter, r *http.Request) {
header.Set(contentType, "text/html; charset=UTF-8")
header.Set("X-Content-Type-Options", "nosniff")
header.Set("Referrer-Policy", "same-origin") // Only expose the referring url when navigating around the satellite itself.
}
var path string
if server.config.UseVuetifyProject {
path = filepath.Join(server.config.StaticDir, "dist_vuetify_poc", "index-vuetify.html")
} else {
path = filepath.Join(server.config.StaticDir, "dist", "index.html")
}
// appHandler is web app http handler function.
func (server *Server) appHandler(w http.ResponseWriter, r *http.Request) {
server.setAppHeaders(w, r)
path := filepath.Join(server.config.StaticDir, "dist", "index.html")
file, err := os.Open(path)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
@ -453,7 +455,6 @@ func (server *Server) appHandler(w http.ResponseWriter, r *http.Request) {
} else {
server.log.Error("error loading index.html", zap.String("path", path), zap.Error(err))
}
// Loading index is optional.
return
}
@ -472,6 +473,36 @@ func (server *Server) appHandler(w http.ResponseWriter, r *http.Request) {
http.ServeContent(w, r, path, info.ModTime(), file)
}
// vuetifyAppHandler is web app http handler function.
func (server *Server) vuetifyAppHandler(w http.ResponseWriter, r *http.Request) {
server.setAppHeaders(w, r)
path := filepath.Join(server.config.StaticDir, "dist_vuetify_poc", "index-vuetify.html")
file, err := os.Open(path)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
server.log.Error("index-vuetify.html was not generated. run 'npm run build-vuetify' in the "+server.config.StaticDir+" directory", zap.Error(err))
} else {
server.log.Error("error loading index-vuetify.html", zap.String("path", path), zap.Error(err))
}
return
}
defer func() {
if err := file.Close(); err != nil {
server.log.Error("error closing index-vuetify.html", zap.String("path", path), zap.Error(err))
}
}()
info, err := file.Stat()
if err != nil {
server.log.Error("failed to retrieve index-vuetify.html file info", zap.Error(err))
return
}
http.ServeContent(w, r, path, info.ModTime(), file)
}
// withAuth performs initial authorization before every request.
func (server *Server) withAuth(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

View File

@ -5,7 +5,7 @@ import { createRouter, createWebHistory } from 'vue-router';
const routes = [
{
path: '/',
path: '/vuetifypoc',
redirect: { path: '/dashboard' },
component: () => import('@poc/layouts/Default.vue'),
children: [