Hi guys… Just set up Hugo on my VM and trying it out… I set my baseurl to an ip like 192.168.1.135 in the config.json and hugo appears to simple ignore it and go with localhost… but it works fine when I use the “-b” option to specify… what could be wrong? I also tried specifying my config file using “–config”… nothing!
Not sure, but instead of fighting it, I would walk the easy route - set up a proper host name.
You mean by editing
/etc/hosts? I guess I’m just not satisfied that setting up the host name is the only solution
Well, you should also report an issue at GitHub.
It may be a matter of taste, but I always prefer having a host name, even for local servers.
And in your case, it would be a faster fix han waiting for a patch. Writing the patch yourself is one way, too, of course.
the behavior is by design. Config is meant for generation. Serving is intended for development. Serving also works in production well, but its a much less common use case. Can override the behavior with a flag as you found.
There’s probably a better approach, but this one was designed for the least friction for the most common use cases.
I opened an issue on github according to this recently. I think the behaviour regarding the BaseUrl parameter is very confusing. The “better approach” you mentioned could be to respect the BaseUrl defined in the configuration also for serving the content. If there is no baseurl defined the server still can fallback to its current behaviour.
The current behaviour results in a difference between the content which is built and the content which is served. I think this is a problematic decision especially when “serving is intended for development”. At least I do not expect a difference between the files generated when running
hugo server --watch - do you?
I can agree that it can be confusing, but not once you know how it works.
And once you know how it works, you kind of appreciate it.
- config.toml is my production settings
- I’m not that keen on duplicate that just to override the baseUrl
- hugo server (with or without watch) defaults to localhost. This is what most people use in development and is stated in the log on startup.
hugo server --baseUrl=http://0.0.0.0:1234covers the rest of the use cases
If we remove the logic in bullet 3 above, you will get what you want, but we will get a truck load of even more confused users who doesn’t use a virtual Ubuntu server with no localhost …
So this boils down to the choice with less confusion, I guess.
I prefer solutions which are intuitive. Of course this is always very subjective. It took me time to discover this behaviour and I just don’t see a benefit in it.
- Okay, same here (work in progress).
- What is the use case for using different BaseUrls for development and production? What are you using the BaseUrl for? The only use case for differential BaseUrls I see at the moment is for the feed where one need to specify an absolute uri (reference). For me this seems bearable if it “breaks” in development environment. So using the BaseUrl needed for the production environment seems okay, no need to duplicate configuration.
- Shouldn’t people use host and port independent urls? This allows you to serve content no matter on wich port your server runs and thus also works with
https://. You don’t have to care about the domain or IP the content is requested from, too. There are so many benefits. What are the benefits of absolute urls? Easy parsing, mh? There are just a few use cases where you could really need the baseurl and in this situations it will break in environments like mine because of the server behaviour. If you don’t know about this specific server behaviour in these situations you will start scratching your head.
- I see the workarounds. I just do not understand the benefit in having differences in the resulting output.
Guess I will just avoid using the Hugo server and use a standalone server as this should work best for me.
I have not read all your points too carefully, but I believe a site of mine will illustrate it:
I have a blog at http://bepsays.com – so:
– the baseurl in config.toml is http://bepsays.com (production value)
– but since the font provider do domain validation I also have to have a domain when testing it so I do
hugo server --baseUrl=http://somebep.local
– If I did not need the above, I could just do
In both of the last two cases above I needed something different than the production value for
.Site.BaseUrl to make any sense.
And I really doesn’t understand the “have to use the standalone server” thingy. What is wrong with adding the baseulr to the server options at startup?
On an added note:
I see many of your arguments is based on that the
BaseUrl variable isn`t really needed.
Many people use it (me included)… What are the benefits of absolute urls? RSS?
Using the --baseUrl argument in the server command is not enough to generate a production version of you website. The port number is still inserted in the url. To remove this, you need to add --appendPort=false to your command
hugo server --baseUrl=http://example.com --appendPort=false