Skip to the page

Share a Hugo site: hugo server, links and live reload

hugo server loads through a link, but its links say localhost and live reload dials the wrong port. Three flags fix both; or upload public.

Updated

hugo server loads through a ouicu link, but it writes your laptop's address into every link on the page, and its live reload dials a port the link doesn't have. Start it with the link's address and three flags and both work. For a client who looks later, build with that address and upload public.

Hugo at a glance
Hugo
Dev server port1313
On your Wi-Fihugo server --bind 0.0.0.0
Host checkNone
Build folder to uploadpublic, from hugo
Hugo through a ouicu link
Through the linkWhat it takes
The pageNeeds --baseURL https://<name>.ouicu.app/ --appendPort=false --liveReloadPort=443
Hot reloadNeeds --baseURL https://<name>.ouicu.app/ --appendPort=false --liveReloadPort=443
A POSTNothing to test

Hugo builds absolute links from its baseURL, which the configuration reference defines as “The absolute URL of your published site including the protocol, host, path, and a trailing slash.” hugo server swaps in its own address, so through the link a page's .Permalink said http://localhost:1313/. The page itself loads, since ouicu reaches the server on localhost, but a menu or a post list built from permalinks sends your client to their own computer.

Live reload dials the wrong port

Hugo adds a live reload script to each page, and it connects to the dev server's port. Through the link that becomes wss://calm-otter-4821.ouicu.app:1313/livereload, a port the link doesn't answer on, so the socket never opens and saves never show. The flag for this is in Hugo's own help, which describes it as:

“port for live reloading (i.e. 443 in HTTPS proxy situations) (default -1)”

Hugo docs, hugo server

A link is exactly that situation: https on the standard port, with ouicu in front. Both problems are quiet ones. The first page looks right, and nothing says live reload failed; you only notice when a click or a save goes nowhere.

Start the share first, so you know the address, then start Hugo with it. A share with nothing behind it yet just waits:

ouicu share 1313# in a second terminal, with the address it printedhugo server --baseURL https://calm-otter-4821.ouicu.app/ --appendPort=false --liveReloadPort=443

--appendPort=false keeps Hugo from adding :1313 to that address; its help gives it as “append port to baseURL (default true)”. With the three flags, the permalink said https://calm-otter-4821.ouicu.app/, live reload connected to wss://calm-otter-4821.ouicu.app/livereload, and a saved template reloaded the page on its own. On Free the name is new each share; with a name you keep, on Hobby and Pro, the command stays the same: ouicu share 1313 --name studiolund.

Hugo says where it listens as it starts, your computer alone:

In the terminal
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)

That's all ouicu needs, and Hugo has no host check to pass. On Free, a share runs for up to 2 hours. For a phone on your Wi-Fi without a link, Hugo needs hugo server --bind 0.0.0.0; the QR code ouicu prints doesn't (QR codes, how to open localhost on your phone).

Upload the build instead

A Hugo site is static, so the build can go up and stay up with your laptop closed. hugo writes it to public, with links on baseURL, and a new site's hugo.toml still has the placeholder, https://example.org/: our build's permalink said exactly that. Build with the address you'll upload to instead:

hugo --baseURL https://studiolund.ouicu.app/ouicu deploy public --name studiolund

With a reserved name you know the address before you build. On Free, upload once to get an address, build again with it, and upload again with --name and that site's name to replace it (Uploading a built site, names).

Keep it to the people you send it to

A link reaches every page the server builds. Hugo's docs are frank about the server itself: “While hugo server is high performance, it is a webserver with limited options.” So for a client, ask for a password, on Hobby and Pro: ouicu share 1313 --password. ouicu asks before a request reaches Hugo.

Tested with Hugo 0.167.0 on , with the release binary for linux-amd64: a site from hugo new site with a home page of our own, served by hugo server and shared with ouicu share through ouicu's edge, opened in Chromium at its https link before and after the three flags, and built with and without --baseURL.

Sources

Prices, defaults and quotes about other products, and the day each was last checked at its source.

  1. hugo server, Hugo docs. Checked .
  2. All settings, Hugo docs. Checked .
  3. commands/server.go, Hugo on GitHub. Checked .