import express from "express";
import { createProxyMiddleware } from "http-proxy-middleware";
const app = express();
app.use(express.json());
const MOCK = process.env.MOCK_MODE === "true";
if (!MOCK) {
app.use("/v1", createProxyMiddleware({
target: process.env.LINKTREE_BASE_URL,
changeOrigin: true,
headers: { Authorization: `Bearer ${process.env.LINKTREE_API_KEY}` },
}));
} else {
const { mountMockRoutes } = require("./mocks");
mountMockRoutes(app);
}
app.listen(3005, () => console.log(`Linktree dev server on :3005 [mock=${MOCK}]`));
export function mountMockRoutes(app: any) {
app.get("/v1/profile", (_req: any, res: any) => res.json({
id: "usr_1", username: "janedoe", displayName: "Jane Doe", bio: "Designer & creator",
links: [
{ id: "lnk_1", title: "Portfolio", url: "https://jane.design", position: 0, enabled: true },
{ id: "lnk_2", title: "Shop", url: "https://shop.jane.design", position: 1, enabled: true },
{ id: "lnk_3", title: "Newsletter", url: "https://jane.substack.com", position: 2, enabled: false },
],
}));
app.get("/v1/analytics", (_req: any, res: any) => res.json({
totalViews: 12450, totalClicks: 3280, clickRate: 0.263,
topLinks: [{ id: "lnk_1", title: "Portfolio", clicks: 1890 }],
}));
app.put("/v1/links/:id", (req: any, res: any) => res.json({ id: req.params.id, ...req.body, updatedAt: new Date().toISOString() }));
}