My Vercel production build is just outputting the contents of my compiled index.js:
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const express_1 = __importDefault(require("express"));
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
require("dotenv/config");
const posts_1 = require("./posts");
const app = (0, express_1.default)();
const PORT = process.env.PORT;
const postsService = new posts_1.PostsService();
// Serve static files (CSS, JS, images, etc.)
app.use("/static", express_1.default.static(path_1.default.join(__dirname, "static")));
app.get("/", (_, res) => {
const homePath = path_1.default.join(__dirname, "home.html");
let homeContent = fs_1.default.readFileSync(homePath, "utf8");
// Get all posts
const posts = postsService.getAllPosts();
// Generate HTML for posts
const postsHtml = posts.length === 0
? "<p>No posts found.</p>"
: posts
.map((post) => `<li><a href="${post.url}">${post.title}</a></li>`)
.join("");
// Replace placeholder in home.html
homeContent = homeContent.replace("{{posts}}", postsHtml);
res.send(homeContent);
});
// Serve individual blog posts (markdown rendered with template)
app.get("/blog/:slug", (req, res) => {
const slug = req.params.slug;
const postPath = path_1.default.join(__dirname, "posts", `${slug}.md`);
if (fs_1.default.existsSync(postPath)) {
try {
const postData = postsService.getPostData(`${slug}.md`);
const renderedPost = postsService.renderPost(postData);
res.send(renderedPost);
}
catch (error) {
console.error("Error rendering post:", error);
res
.status(500)
.send('<h1>Error loading post</h1><a href="/">Back to home</a>');
}
}
else {
res
.status(404)
.send('<h1>Blog post not found</h1><a href="/">Back to home</a>');
}
});
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
exports.default = app;
My vercel.json config file looks like this:
{
"$schema": "https://openapi.vercel.sh/vercel.json",
"version": 2,
"rewrites": [{ "source": "/(.*)", "destination": "/api" }],
"outputDirectory": "dist",
"devCommand": "npm run dev",
"buildCommand": "npm run build"
}
I'm using express, and attempting to host a simple blog page. When I run vercel dev locally, it works. I can also npm run dev locally and it works.