Forem

Matt Layman
Matt Layman

Posted on • Originally published at mattlayman.com

WhiteNoise Shenanigans - Building SaaS #79

In this episode, I worked on a method of adding static content to a site that didn't involve the staticfiles directory, a separate domain, or a reverse proxy like Nginx. We had to get clever with Heroku buildpacks and how to configure WhiteNoise.

I want to put a blog on my side project for content marketing purposes.

I want the blog to be statically generated and have content come from Markdown (just like these show notes that you're currently reading).

My preference is to put the blog on a path like mysite.com/blog/ instead of using a subdomain like blog.mysite.com.

I could do this easily if the blog lived at /static/blog/ by working within Django's staticfiles system, but those URLs look gross.

I could also do this with a reverse proxy like Nginx, but that complicates my Heroku deployment setup.

Instead of picking any of those strategies, I wanted to find a way to make WhiteNoise, the package that serves static files in my Django app, serve the blog.

To get started, I added a Heroku buildpack that would run Hugo to generate the blog output. This took a while to get right because I had to create a Hugo project in a way that didn't pollute the root of my project with a bunch of Hugo directories.

Once I was successful with Hugo, we moved on to the WhiteNoise setup. I created a custom subclass of the WhiteNoise middleware so that I could add the blog output to the set that WhiteNoise would serve.

We got the middleware set up and I proved that the app could serve the blog. To finish off the stream, I did some validation of the cache headers to see the behavior of the blog files and how WhiteNoise would cache the files.

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay