Skip to content

Commit

Permalink
templates(base): add vConsole for debug
Browse files Browse the repository at this point in the history
  • Loading branch information
wuhan005 committed Aug 31, 2024
1 parent 6caa5cc commit 2e923a3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ func Contexter() flamego.Handler {
c.Data["CurrentURI"] = ctx.Request().Request.RequestURI
c.Data["ExternalURL"] = conf.App.ExternalURL

// ⚠️ VConsole can only be enabled for the first user for security reasons.
c.Data["VConsole"] = ctx.Query("debug") == "on" && c.IsLogged && c.User.ID == 1

// 🚨 SECURITY: Prevent MIME type sniffing in some browsers,
c.ResponseWriter().Header().Set("X-Content-Type-Options", "nosniff")
c.ResponseWriter().Header().Set("X-Frame-Options", "DENY")
Expand Down
7 changes: 5 additions & 2 deletions templates/base/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
type="application/javascript"></script>
<script defer src="https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/html2canvas/1.4.1/html2canvas.min.js"
type="application/javascript"></script>
<script defer src="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/alpinejs/3.9.0/cdn.min.js"/>
</script>
<script defer src="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/alpinejs/3.9.0/cdn.min.js"/></script>
{{ if .VConsole }}
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/vConsole/3.12.1/vconsole.min.js" type="application/javascript"></script>
<script>new window.VConsole()</script>
{{ end }}
{{ if .RecaptchaTurnstileStyle }}
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js?compat=recaptcha" async defer></script>
<script>
Expand Down

0 comments on commit 2e923a3

Please sign in to comment.