import type { NextApiRequest, NextApiResponse } from "next"; import { WEBAPP_URL } from "@calcom/lib/constants"; export default async function handler(req: NextApiRequest, res: NextApiResponse) { if (req.method === "POST") { // Set Content-Type header to text/html res.setHeader("Content-Type", "text/html"); const url = req.query.url as string; if (!url) return res.status(400).json({ message: "Missing URL in query parameters" }); res.setHeader("Content-Type", "text/html"); let origin = WEBAPP_URL; let calLink = url; if (/^https?:\/\//i.test(url)) { try { const parsedUrl = new URL(url); const hostname = parsedUrl.hostname.toLowerCase(); if (hostname === "cal.com" || hostname.endsWith(".cal.com")) { origin = parsedUrl.origin; calLink = parsedUrl.pathname + parsedUrl.search; if (calLink.startsWith("/")) { calLink = calLink.substring(1); } } else { return res.status(400).json({ message: "URL must be for cal.com or a subdomain of cal.com" }); } } catch { return res.status(400).json({ message: "Invalid URL format" }); } } else { calLink = url.replace(`${WEBAPP_URL}/`, ""); } // Generate HTML with embedded Cal component const htmlResponse = ` Cal.com
`; res.status(200).send(htmlResponse); } else { res.status(405).end(); // Method Not Allowed } }