Skip to content
Snippets Groups Projects
Commit e0bbdfdc authored by Mo Firouz's avatar Mo Firouz Committed by Andrei Mihu
Browse files

Fix dashboard paths.

parent d8df7566
Branches
Tags
No related merge requests found
Source diff could not be displayed: it is too large. Options to address this: view the blob.
......@@ -20,4 +20,5 @@ import (
"github.com/gobuffalo/packr"
)
var UI = http.FileServer(packr.NewBox("./ui/build")) // path must be string not a variable for packr to understand
var BoxFS = packr.NewBox("./ui/dist") // path must be string not a variable for packr to understand
var UI = http.FileServer(BoxFS)
......@@ -59,8 +59,8 @@
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
"maximumWarning": "1mb",
"maximumError": "2mb"
},
{
"type": "anyComponentStyle",
......
......@@ -15,7 +15,7 @@
<div class="btn-group">
<button type="button" class="btn btn-primary dropdown-radius" (click)="f.filter_type.setValue(0); search(0)">Search</button>
<div class="btn-group" ngbDropdown role="group" aria-label="Button group with nested dropdown">
<button [disabled]="!f.filter.value || f.filter.value === ''" class="btn btn-primary dropdown-toggle-split" ngbDropdownToggle></button>
<button type="button" [disabled]="!f.filter.value || f.filter.value === ''" class="btn btn-primary dropdown-toggle-split" ngbDropdownToggle></button>
<div class="dropdown-menu" ngbDropdownMenu>
<button type="button" ngbDropdownItem (click)="f.filter_type.setValue(1); search(0)">Tombstones</button>
</div>
......
......@@ -15,4 +15,5 @@
export const environment = {
production: true,
segment_write_key: 'dHl7FTjJ9icepBjEdOCcyMFQYL1BBiQO',
apiBaseUrl: '',
};
......@@ -19,9 +19,11 @@ import (
"crypto"
"database/sql"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/http/pprof"
"path/filepath"
"sort"
"strings"
"time"
......@@ -159,12 +161,6 @@ func StartConsoleServer(logger *zap.Logger, startupLogger *zap.Logger, db *sql.D
}
grpcGatewayRouter := mux.NewRouter()
grpcGatewayRouter.Handle("/", console.UI).Methods("GET")
grpcGatewayRouter.Handle("/manifest.json", console.UI).Methods("GET")
grpcGatewayRouter.Handle("/favicon.ico", console.UI).Methods("GET")
grpcGatewayRouter.PathPrefix("/static/").Handler(console.UI).Methods("GET")
//zpagesMux := http.NewServeMux()
//zpages.Handle(zpagesMux, "/metrics/")
//grpcGatewayRouter.NewRoute().PathPrefix("/metrics").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
......@@ -187,7 +183,7 @@ func StartConsoleServer(logger *zap.Logger, startupLogger *zap.Logger, db *sql.D
r.Body = http.MaxBytesReader(w, r.Body, maxMessageSizeBytes)
handlerWithCompressResponse.ServeHTTP(w, r)
})
grpcGatewayRouter.NewRoute().HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
grpcGatewayRouter.NewRoute().PathPrefix("/v2").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Ensure some headers have required values.
// Override any value set by the client if needed.
r.Header.Set("Grpc-Timeout", gatewayContextTimeoutMs)
......@@ -195,6 +191,7 @@ func StartConsoleServer(logger *zap.Logger, startupLogger *zap.Logger, db *sql.D
// Allow GRPC Gateway to handle the request.
handlerWithMaxBody.ServeHTTP(w, r)
})
registerDashboardHandlers(logger, grpcGatewayRouter)
// Enable CORS on all requests.
CORSHeaders := handlers.AllowedHeaders([]string{"Authorization", "Content-Type", "User-Agent"})
......@@ -274,6 +271,40 @@ func StartConsoleServer(logger *zap.Logger, startupLogger *zap.Logger, db *sql.D
return s
}
func registerDashboardHandlers(logger *zap.Logger, router *mux.Router) {
router.PathPrefix("/").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// get the absolute path to prevent directory traversal
path := filepath.Join("/ui", r.URL.Path) // no slash needed because it already comes from the root
logger = logger.With(zap.String("url_path", r.URL.Path), zap.String("path", path))
// check whether a file exists at the given path
if console.BoxFS.Has(path) {
// otherwise, use http.FileServer to serve the static dir
r.URL.Path = path // override the path with the prefixed path
console.UI.ServeHTTP(w, r)
return
} else {
indexFile, err := console.BoxFS.Open("ui/index.html")
if err != nil {
logger.Error("Failed to open index file.", zap.Error(err))
w.WriteHeader(http.StatusNotFound)
return
}
indexBytes, err := ioutil.ReadAll(indexFile)
if err != nil {
logger.Error("Failed to read index file.", zap.Error(err))
w.WriteHeader(http.StatusNotFound)
return
}
w.Header().Add("Cache-Control", "no-cache")
w.Write(indexBytes)
return
}
})
}
func (s *ConsoleServer) Stop() {
s.ctxCancelFn()
// 1. Stop GRPC Gateway server first as it sits above GRPC server.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment