Using Hugo Server as Preview Server

Hey guys I was wondering if anyone has tried using ‘Hugo server’ as a preview environment for editors. I know ‘Hugo server’ is primarily a dev server, but I’m thinking since it’s not going to be facing website visitors it might work in this situation.

In my particular case I’m using Contentful. I’ve done a couple sites using Contentful and Hugo which has been a breeze, but for site Previews I’ve basically been maintaining a completely custom preview environment which has created some redundant work on my end.

So I started to become curious if I could just do both environments (production and preview) using Hugo. The idea is the machine running ‘Hugo server’ would receive webhooks from Contentful and run a script that pulls data from the preview API on each webhook. ‘Hugo server’ would then detect the changes and hot-reload the site.

Some potential pitfalls:
I have no idea how resource intensive Hugo server is. At the same time Contentful auto-saves for every single change which will lead to a lot of webhooks being sent to the server. It would result in a lot of changes happening very quickly. I’m not sure what kind of limitations Hugo server has.

What do you guys think? Does anyone have any insight into this?

I’ve already read through this thread here: [SOLVED] Hugo Server for Production Revisited, but thought my topic was a little different in nature.

What is a preview server?

As in a server that lets editors preview content before hitting publish. Idk maybe preview server is the wrong terminology, but here’s GIF of what I mean.

This is a preview environment I set up for a client’s website. The public facing website is built with Hugo while the environment showing the previews is something I had to make custom. It’s basically a web app but the styling is exactly the same (or mostly the same) as the website.

So I’m basically wondering is instead of doing this if I can run ‘Hugo server’ on a server and have it constantly rebuild the website when new changes are made. At least that’s the idea. It would save me from maintaining two separate environments. I know ‘Hugo server’ was never meant for production, but I thought it could maybe be used on a ‘live environment’ in this case.

Yes, you can use hugo server like that.

I presumed most folks used the built-in dev server to preview their sites locally, on their PCs. That’s what I do. Cheers. :slight_smile:

I presumed most folks used the built-in dev server to preview their sites locally, on their PCs. That’s what I do. Cheers. :slight_smile:

Yes I’m aware of previewing locally I run Hugo server all the time when I develop. This is mainly so that editors can immediately preview from the CMS without generating a full rebuild.

I guess I was mainly concerned about the potential server resources needed if Hugo server is getting a webhook to rebuild every second or even several times a second.

Contentful autosaves as you type and it sends a webhook for each autosave. I was thinking if an editor is typing, or even say 3 editors are typing on different articles it could really tax the server since it’ll be triggering a ton of rebuilds. I just realize maybe I could create a filter or something where it’ll only rebuild once every 5 seconds or something. That could be the solution.

So I actually reached out to Contentful and found out that the webhook for auto-saves only fires every 20 seconds, even though it auto-saves immediately. So I think this will actually work out :raised_hands:. I’m going to experiment with this and post my results later.