import type { Express } from "express"; import { createServer, type Server } from "http"; import { storage } from "./storage"; import { insertNewsletterSchema } from "@shared/schema"; import { z } from "zod"; export async function registerRoutes(app: Express): Promise { // Newsletter subscription endpoint app.post("/api/newsletter/subscribe", async (req, res) => { try { const validatedData = insertNewsletterSchema.parse(req.body); const newsletter = await storage.subscribeNewsletter(validatedData); res.json({ success: true, message: "Successfully subscribed to newsletter" }); } catch (error) { if (error instanceof z.ZodError) { res.status(400).json({ success: false, message: "Invalid email address" }); } else if (error instanceof Error && error.message === "Email already subscribed") { res.status(409).json({ success: false, message: "Email is already subscribed" }); } else { res.status(500).json({ success: false, message: "Internal server error" }); } } }); const httpServer = createServer(app); return httpServer; }