Hugo baseUrl for preview environment

I am struggling with setting up CF Pages’ preview environment that would have proper baseUrl. I use develop branch so I have fixed environment alias. However all links in generated page are based on my production baseUrl which is provided in configuration. Hugo can serve development instance locally and handle URLs even though baseUrl is set, so it should be possible also on CF Pages.

I’ve tried to use -b flag in Pages’ build command, but it does not work and even if it did, it would impact production builds most probably, so it can’t be used.

Is it possible to change baseUrl for preview environment only?

Use the CF_PAGES_URL variable to tell your build tools what URL Pages will be serving your site on.

https://developers.cloudflare.com/pages/platform/build-configuration/#environment-variables

1 Like

I’ve added this env variable few minutes ago and retried deployment. I see proper CF_PAGES_URL in build config (in deployment details), but later in build log I see that baseUrl from my config is used and links are still invalid. FYI: I don’t use global baseUrl but per-language config, does it matter? Or maybe I should trigger new preview build with new commit instead of retrying previous build?

I was able to override baseURL by using HUGO_LANGUAGES_pl_baseurl env variable set in CF Pages’ “Environment variables” settings section. Now all links in preview environment point to this specific environment so site is navigable :slight_smile:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.