mirror of
https://github.com/Threnklyn/wg-ui.git
synced 2026-06-06 22:00:09 +02:00
Fix embedded assets, particularly when serving UI/App urls
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
binary:
|
||||
.PHONY: binary container ui
|
||||
|
||||
binary: ui
|
||||
go-bindata-assetfs -prefix ui/public ui/public
|
||||
go build .
|
||||
|
||||
ui:
|
||||
cd ui && npm install && npm run build
|
||||
|
||||
container:
|
||||
docker build -t wireguard-ui .
|
||||
|
||||
|
||||
@@ -288,6 +288,9 @@ func (s *Server) Start() error {
|
||||
log.Debug("Serving static assets proxying from development server: ", *devUIServer)
|
||||
devProxy := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
url, _ := url.Parse(*devUIServer)
|
||||
if strings.HasPrefix(r.URL.Path, "/client/") || r.URL.Path == "/about" {
|
||||
r.URL.Path = "/"
|
||||
}
|
||||
proxy := httputil.NewSingleHostReverseProxy(url)
|
||||
r.URL.Host = url.Host
|
||||
r.URL.Scheme = url.Scheme
|
||||
@@ -298,6 +301,8 @@ func (s *Server) Start() error {
|
||||
router.NotFound = devProxy
|
||||
} else {
|
||||
log.Debug("Serving static assets embedded in binary")
|
||||
router.GET("/about", s.Index)
|
||||
router.GET("/client/:client", s.Index)
|
||||
router.NotFound = s.assets
|
||||
}
|
||||
|
||||
@@ -371,6 +376,12 @@ func (s *Server) GetClients(w http.ResponseWriter, r *http.Request, ps httproute
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
log.Debug("Serving single-page app from URL: ", r.URL)
|
||||
r.URL.Path = "/"
|
||||
s.assets.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
func (s *Server) GetClient(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
user := r.Context().Value("user").(string)
|
||||
usercfg := s.Config.Users[user]
|
||||
|
||||
@@ -8,13 +8,13 @@
|
||||
|
||||
<link rel="stylesheet" href="https://unpkg.com/bootstrap-material-design@4.1.1/dist/css/bootstrap-material-design.min.css" integrity="sha384-wXznGJNEXNG1NFsbm0ugrLFMQPWswR3lds2VeinahP8N0zJw9VWSopbjv2x7WCvX" crossorigin="anonymous">
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||
<link rel='icon' type='image/png' href='favicon.png'>
|
||||
<link rel='stylesheet' href='global.css'>
|
||||
<link rel='stylesheet' href='bundle.css'>
|
||||
<link rel='icon' type='image/png' href='/favicon.png'>
|
||||
<link rel='stylesheet' href='/global.css'>
|
||||
<link rel='stylesheet' href='/bundle.css'>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<script src='bundle.js'></script>
|
||||
<script src='/bundle.js'></script>
|
||||
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
|
||||
<script src="https://unpkg.com/popper.js@1.12.6/dist/umd/popper.js" integrity="sha384-fA23ZRQ3G/J53mElWqVJEGJzU0sTs+SvzG8fXVWP+kJQ1lwFAOkcUOysnlKJC33U" crossorigin="anonymous"></script>
|
||||
<script src="https://unpkg.com/bootstrap-material-design@4.1.1/dist/js/bootstrap-material-design.js" integrity="sha384-CauSuKpEqAFajSpkdjv3z9t8E7RlpJ1UP0lKM/+NdtSarroVKu069AlsRPKkFBz9" crossorigin="anonymous"></script>
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
const { createServer } = require("http");
|
||||
const app = require("./dist/App.js");
|
||||
const app = require("./App.js");
|
||||
|
||||
createServer((req, res) => {
|
||||
const { html } = app.render({ url: req.url });
|
||||
@@ -7,7 +7,7 @@ createServer((req, res) => {
|
||||
res.write(`
|
||||
<!DOCTYPE html>
|
||||
<body>${html}</body>
|
||||
<script src="/dist/bundle.js"></script>
|
||||
<script src="/bundle.js"></script>
|
||||
`);
|
||||
|
||||
res.end();
|
||||
|
||||
Reference in New Issue
Block a user