mirror of
https://github.com/Threnklyn/wg-ui.git
synced 2026-06-02 19:59:18 +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 .
|
go build .
|
||||||
|
|
||||||
|
ui:
|
||||||
|
cd ui && npm install && npm run build
|
||||||
|
|
||||||
container:
|
container:
|
||||||
docker build -t wireguard-ui .
|
docker build -t wireguard-ui .
|
||||||
|
|
||||||
|
|||||||
@@ -288,6 +288,9 @@ func (s *Server) Start() error {
|
|||||||
log.Debug("Serving static assets proxying from development server: ", *devUIServer)
|
log.Debug("Serving static assets proxying from development server: ", *devUIServer)
|
||||||
devProxy := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
devProxy := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
url, _ := url.Parse(*devUIServer)
|
url, _ := url.Parse(*devUIServer)
|
||||||
|
if strings.HasPrefix(r.URL.Path, "/client/") || r.URL.Path == "/about" {
|
||||||
|
r.URL.Path = "/"
|
||||||
|
}
|
||||||
proxy := httputil.NewSingleHostReverseProxy(url)
|
proxy := httputil.NewSingleHostReverseProxy(url)
|
||||||
r.URL.Host = url.Host
|
r.URL.Host = url.Host
|
||||||
r.URL.Scheme = url.Scheme
|
r.URL.Scheme = url.Scheme
|
||||||
@@ -298,6 +301,8 @@ func (s *Server) Start() error {
|
|||||||
router.NotFound = devProxy
|
router.NotFound = devProxy
|
||||||
} else {
|
} else {
|
||||||
log.Debug("Serving static assets embedded in binary")
|
log.Debug("Serving static assets embedded in binary")
|
||||||
|
router.GET("/about", s.Index)
|
||||||
|
router.GET("/client/:client", s.Index)
|
||||||
router.NotFound = s.assets
|
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) {
|
func (s *Server) GetClient(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
user := r.Context().Value("user").(string)
|
user := r.Context().Value("user").(string)
|
||||||
usercfg := s.Config.Users[user]
|
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 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 href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||||
<link rel='icon' type='image/png' href='favicon.png'>
|
<link rel='icon' type='image/png' href='/favicon.png'>
|
||||||
<link rel='stylesheet' href='global.css'>
|
<link rel='stylesheet' href='/global.css'>
|
||||||
<link rel='stylesheet' href='bundle.css'>
|
<link rel='stylesheet' href='/bundle.css'>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<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://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/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>
|
<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 { createServer } = require("http");
|
||||||
const app = require("./dist/App.js");
|
const app = require("./App.js");
|
||||||
|
|
||||||
createServer((req, res) => {
|
createServer((req, res) => {
|
||||||
const { html } = app.render({ url: req.url });
|
const { html } = app.render({ url: req.url });
|
||||||
@@ -7,7 +7,7 @@ createServer((req, res) => {
|
|||||||
res.write(`
|
res.write(`
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<body>${html}</body>
|
<body>${html}</body>
|
||||||
<script src="/dist/bundle.js"></script>
|
<script src="/bundle.js"></script>
|
||||||
`);
|
`);
|
||||||
|
|
||||||
res.end();
|
res.end();
|
||||||
|
|||||||
Reference in New Issue
Block a user