Using different params while running hugo server on localhost?

I am planning to host assets(css, js, png etc,) on <subdomains>.mydomain.com. I am making these assets using node.js ecosystem. I want to test these files as I edit them in editor along with hugo.

Initially, I put all of subdomain urls to /etc/hosts, But to bind these domains to port 80, I need root access. I am having trouble doing that.

Alternatively, I know that I can use two different config like hugo server -w --config="config-dev.toml" with different assetUrl params. But while updating other params, I will have to update at two places. I really don’t like data redundancy.

Can I swap url like baseUrl param can, to some localhost:port value while running hugo server -w?

Try

hugo help server

the -b and -p options should get you there, if I understand you correctly.

@bjornerik That will not work for me.

I have config.toml with params like

[params]
    assetUrl = "//assets.mydomain.com"

I am using this params in layouts template like

<script src="{{ .Site.Params.assetUrl }}/script.js"></script>

I am making this script using nodejs. So, I run this command I get something like

$ gulp watch
serving files from 'assetsBuild/'
serving at http://localhost:3000

Then, I run hugo server -w which is runs on localhost:1313.

I then point my assets.mydomain.com to ip like 127.0.0.11 in /etc/hosts
and tries to bind my nodejs script to port 80.
But, that is failing because of permission issues.

So, It strikes to me, If hugo can somehow replace urls from .Site.Params.assetUrl
to localhost:3000 when running hugo server -w, problem will be solved.
Exactly like baseUrl params gets changed to localhost:1313.

I am not able to find this kind of feature in hugo docs. I am looking for some workarounds.

OK, now I understand … from top of my head I cannot see an obvious workaround. Others may chip in - @spf13 will know. Overriding params from command line would be cool, I guess, but I don’t think that’s possible.

Yep, that will be useful.

OR, I am thinking If hugo devs can add a feature in config like this

[params]
    assetsUrl = "//assets.mydomain.com"
    otherParam = "some value"

[[params.server]]
    assetsUrl = "localhost:3000"

where, keys in [[params.server]] replaces matching keys in [params], while running hugo server command. and in template there is no change needed i.e. {{ .Site.Params.assetUrl }} works as usual.

2 Likes