Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live reload not working - reload script not injected #667

Open
pczern opened this issue Oct 19, 2024 · 2 comments
Open

Live reload not working - reload script not injected #667

pczern opened this issue Oct 19, 2024 · 2 comments

Comments

@pczern
Copy link

pczern commented Oct 19, 2024

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
Copy link
Author

pczern commented Oct 19, 2024

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
Copy link

istyf commented Nov 3, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@pczern @istyf and others