To create this blog, I used Remix, it's a new open source full stack web framework based on javascript. They created a great tutorial and it's fairly easy to get started with it. This blog is based on the developer blog tutorial, where each blog article is an markdown file.
To host this blog I wanted to try Vercel. The process is very smooth but i quickly uncontered the following error :
After a few try, i understood that my md files were not beeing bundle during the build process in vercel.
To get them inside the build i created a new script in my package.json
and moved them inside the public folder like that :
{
...,
scripts: {
build: "remix build && npm run build:md",
build:me: "cp -R posts public"
}
...
Even if the md file are in the build, it's still not working... But I found two discussions refering this error:
In the tutorials, posts are retrieve this way :
const postsPath = path.join(__dirname, "../..", "posts");
export async function getPosts() {
const dir = await fs.readdir(postsPath);
return Promise.all(
dir.map(async filename => {
const file = await fs.readFile(
path.join(postsPath, filename)
);
// ...
}
}
To get it working we only need to change it this way we initialize the postsPath
variable :
const postsPath = `${__dirname}/../../posts`;
Somehow the vercel function cannot scan the directory, if we are using path.join
.