air-verse / air

☁️ Live reload for Go apps
GNU General Public License v3.0
18.29k stars 815 forks source link

Live reload not working - reload script not injected #667

Open pczern opened 1 month ago

pczern commented 1 month ago

Live Reload refresh isn't working in the browser, the go app rebuilds on any changes but the browser isn't reloading.

With GoFiber I am creating a server like

log.Fatal(app.Listen(":3000"))

Rendering the page on route /

app.Get("/", func(c *fiber.Ctx) error {
    return c.Render("page/index", &fiber.Map{}, "layout/layout-default")
})

but when I change anything in "page/index" I have to manually refresh. Checking the source code in the browser via "View Source" shows no injected script for live reload. The layout-default I am rendering the page with contains a <body> element.

# Config file for [Air](https://github.com/cosmtrek/air) in TOML format

# Working directory
# . or absolute path, please note that the directories following must be under root.
root = "."
tmp_dir = "tmp"

[build]
cmd = "task build"
bin = "main"
full_bin = ""
include_ext = ["go", "tpl", "tmpl", "html"]
exclude_dir = ["tmp"]
include_dir = ["src"]
exclude_file = []
exclude_unchanged = false
follow_symlink = false
log = "air.log"
delay = 1000
stop_on_error = true
send_interrupt = true
# Delay after sending Interrupt signal
kill_delay = 0      # ms
poll = false
poll_interval = 500

[log]
time = true
silent = false

[color]
main = "magenta"
watcher = "cyan"
build = "yellow"
runner = "green"

[misc]
clean_on_exit = true

[screen]
clear_on_rebuild = true
keep_scroll = true

[proxy]
enabled = true
proxy_port = 3001
app_port = 3000
pczern commented 1 month ago

It works if I add the script manually to my layout-default, but I think it should be injected automatically for all pages?

<script>new EventSource("http://localhost:3001/internal/reload").onmessage = () => { location.reload() }</script>
istyf commented 2 weeks ago

What is the Content-Type header in your handler's response? The proxy only tries to inject the script in responses that are advertised as text/html.