Skip to content

Commit

Permalink
Render liveview via proxy, it solves the case when service is running…
Browse files Browse the repository at this point in the history
… behind ingress
  • Loading branch information
avakarev committed Jun 11, 2024
1 parent 35552ab commit 38e8afc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 14 additions & 2 deletions internal/web/awtrix/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package awtrix

import (
"fmt"
"strings"
"time"

"github.com/gofiber/fiber/v2"
Expand All @@ -17,7 +18,18 @@ func Routes(app *fiber.App) {
DisablePathNormalizing: true,
})
app.All("/awtrix/:ipv4/*", func(c *fiber.Ctx) error {
url := fmt.Sprintf("http://%s/%s", c.Params("ipv4"), c.Params("*"))
return proxy.DoTimeout(c, url, 1*time.Second)
ipv4 := c.Params("ipv4")
path := c.Params("*")
url := fmt.Sprintf("http://%s/%s", ipv4, path)
if err := proxy.DoTimeout(c, url, 2*time.Second); err != nil {
return err
}
if ctype := string(c.Response().Header.ContentType()); strings.HasPrefix(ctype, "text/html") {
if path == "fullscreen" {
resp := c.Response()
resp.SetBodyString(strings.ReplaceAll(string(resp.Body()), "/api/screen", fmt.Sprintf("/awtrix/%s/api/screen", ipv4)))
}
}
return nil
})
}
4 changes: 2 additions & 2 deletions ui/src/components/awtrix/LiveViewCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="card-header d-flex justify-content-between pe-2">
<span class="d-flex align-items-center text-muted">
LiveView
<a v-if="nodeStore.activeNode" :href="`http://${nodeStore.activeNode.ipv4}/fullscreen`" target="_blank">
<a v-if="nodeStore.activeNode" :href="`/awtrix/${nodeStore.activeNode.ipv4}/fullscreen`" target="_blank">
<i class="bi bi-box-arrow-up-right ms-2" />
</a>
</span>
Expand All @@ -20,7 +20,7 @@
<div class="card-body p-0">
<iframe
v-if="nodeStore.activeNode && awtrixStore.liveViewEnabled"
:src="`http://${nodeStore.activeNode.ipv4}/fullscreen`"
:src="`/awtrix/${nodeStore.activeNode.ipv4}/fullscreen`"
class="border border-2"
width="100%"
title="Display LiveView" />
Expand Down

0 comments on commit 38e8afc

Please sign in to comment.