title: | Migrating the Val Town Blog to Val Town |
---|---|
description: | How we migrated the Val Town Blog from Astro & Cloudflare Pages to be hosted directly on Val Town in a day |
pubDate: | 2025-04-02T00:00:00.000Z |
author: | Steve Krouse |
Today I migrated the Val Town Blog from Astro and Cloudflare Pages to be hosted directly on Val Town. With some cleverness and a bit of vibe coding, I was able to start and complete this migration in a day.
Previously, our blog was:
While this setup worked well, we wanted:
The new blog:
We implemented the new blog system using:
Proxying is as easy as:
const OLD_BLOG_URL = "https://val-town-blog.pages.dev/";
const response = await fetch(
new Request(OLD_BLOG_URL + url.pathname + url.search, {
method: request.method,
headers: new Headers({ ...Object.fromEntries(request.headers) }),
}),
);
We fetch old posts via the https://val-town-blog.pages.dev/rss.xml
,
and combine them with the locally-hosted posts. We cache them both in-memory
on server startup.
// Example of how we fetch blog posts
async function getAllBlogPosts() {
// Get local posts from markdown files
const localPosts = await getLocalBlogPosts();
// Get posts from RSS feed
const rssPosts = await getRssBlogPosts();
// Merge and sort by date
return [...localPosts, ...rssPosts].sort((a, b) => {
return new Date(b.pubDate).getTime() - new Date(a.pubDate).getTime();
});
}
So far we've had reasonable success with this technique of migrating to Val Town quickly by proxying most old content, and only rebuilding the homepage. I first used this technique on my personal website, stevekrouse.com, and was pleased to see it continue to work here. If you, dear reader, have a blog you'd like to migrate to Val Town in this way and get stuck, shoot me an email at steve@val.town – I'd be happy to help.