How to do Proxying During Development?

Following my recent discovery of Disqus’s underhand link hijacking, I’ve been redoubling my efforts to find an alternative to Disqus [long-standing thread --> here].

Anyway, after much wailing and gnashing of teeth, I’ve managed to setup Isso commenting on my server and import my old Disqus comments. So, now that it’s all working , it’s time to start ‘prettying’ it up a bit.

Trouble is, to do this on my local machine, I need to proxy requests to http://localhost.com:1313/isso to the Isso Python script and I can’t work out how to do this.

  • The most straightforward option would seem to be to configure Hugo’s built-in server to do the proxying. But I’m not even sure if this is possible?

  • An alternative would be to run a local webserver on my dev machine, that I could then setup proxying on and have Hugo use that instead of its built-in server, to render the site. But, I’m not sure if this is possible either?

  • A third alternative would be just to; keep re-building the site locally, every so often, quit Hugo’s built-in server and then preview the site using another locally running server with proxying support. But this is going to be a bit of a PITA, especially as I’m just doing HTML/CSS stuff to design the layout of the comments section, so it’s going to be a lot of stop/start incremental changes.

It would be great if I could somehow find a way to avail of Hugo server’s --watch feature to reflect these changes instantly, while at the same time, being able to proxy the Isso requests.

Anyone got any ideas on this?

I don’t think a proxy is what you want (and certainly not something that Hugo’s server supports).

Why not set up

  1. isso on http://isso.myhost
  2. Hugo on http://hugo.myhost

Assuming there are some cross-domain restrictions that got you to start with this proxying in the first place.

Oh well. I didn’t think Hugo’s server would support proxying, but just thought I’d ask in case the magic coding pixies had hidden it as an undocumented feature.

It’s not cross-domain restrictions or anything like that.

Isso is a Python app. It generates the JS files which embed the comments dynamically. So although the Isso comments script for my site is at https://stiobhart.net/isso/js/embed.min.js that file does not actually exist amongst my site files.

Requests for anything under /isso need to be proxied to the Isso app & server running on some other port. Then, I’d assume Isso does the usual web app trick of internally routing those requests to a function which prints out that JS.

Actually, in writing this out, I think I might see a solution…

According to Isso’s developer, the reason Isso does it this way, is so that the embed.min.js file is automatically updated to the newest version, whenever you update Isso, without you having to change any of your static site files. So I’m thinking, I can probably just copy that generated JS to a dummy embed.min.js file residing at that location within my Hugo site setup. Then I’ll not need to do any proxying at all, as the file will actually exist there and so Hugo will be able to access it.

Of course I’ll need to remember to remove the embed.min.js file again, before uploading the site, as it’s not supposed to actually exist. But, in the meantime that should allow me to develop as normal in Hugo, with all the convenience of server --watch.

Off to try it now!..

OK. This is slightly more complex than I thought. It’s easy enough to create a static JS file in my Hugo site at /static/isso/js/embed.min.js, which will cause the Isso interface to be displayed during development. Unfortunately it’s missing existing comments as these are also dynamically injected into the page by the Isso script.

I can easily copy a rendered block of comments from the live site and display it in the appropriate <div> so i can use these for styling with. But obviously I only want to display this [and include the hardcoded embed.min.js file if the site’s running on localhost.

So, why does this not work:

{{if in .Site.BaseURL "localhost" }}
    //show stuff only for dev environment
{{end}}

I suspect it’s because .SiteURL isn’t really a string. But can I cast it to a string?.. or is there some other way to detect if we’re running Hugo locally?

Ah. Found it in another thread:

{{ if eq (printf "%v" $.Site.BaseURL) "http://localhost:1313/" }}
   <!-- code for localhost only -->
{{ end }}

I knew it’d turn out that .Site.BaseURL wasn’t really a string!