Dev, localhost and CORS

Hi there,

I’ve just started with Hugo. I chose the cactus theme (http://themes.gohugo.io/theme/cactus/) and launched the server with hugo server --config config.toml.

When i open the URL in the browser i get a Access to Font at
http://localhost:1313/fonts/MonoSocialIconsFont-1.10.ttf’ from origin
http://localhost:1313’ has been blocked by CORS policy: No
’Access-Control-Allow-Origin’ header is present on the requested
resource. Origin ‘http://127.0.0.1:1313’ is therefore not allowed
access…

Any hits? Should hugo set those headers for me somehow or it’s a theme thing?

Thanks.

@digitalcraftsman may know more, but I see no such errors with that theme on localhost.

Try to use either localhost or 127.0.0.1 in the configuration or try to use relative urls.

Both domains have the same issue.

Can you open localhost:1313 instead of 127.0.0.1:1313 ?

Why isn’t it as simple as satisfying the “CORS policy” it says is doing the blocking?

I tested it locally as well but didn’t encountered the warnings you describe.

@sairam can you confirm this too?

@gonzaloserrano has the problem. He could confirm.

I was just trying to help

I don’t want to deny that @gonzaloserrano has this problems. I just wanted to have a third party that could confirm it and maybe point us to the right direction. The problem is that @bep and I were not able to reproduce the error. This makes it harder to trace the source of the problem.

@digitalcraftsman The theme works fine and as expected when opened as localhost:1313, but not when opened as 127.0.0.1:1313.

I see the font does not load on the latest version of Chrome on Mac OS Sierra which is expected (when opened through 127.0.0.1:1313)

{{ .Site.BaseURL }} is being considered as localhost instead of 127.0.0.1 .

@gonzaloserrano could you provide the browser/OS information?

Ok, this was misunderstanding. Now I face the same message on the console. I tested it with Chrome and Firefox on Linux.

Has anyone figured this out? I cannot get fontawesome icons to load. It is specific to chrome and firefox, however safari does not have this issue. In searching the only work around I’ve found is in creating a .htaccess file but that doesn’t apply to HUGO, or does it? Can’t sort this out.

1 Like

Same problem here, Im trying to make some dataviz with an API, and the cors doesn’t let me test it in localhost

See the -tls* flags here:

You need to run

hugo server trust

First to install a local CA.