From 080faa5ffc3ac321d95c4a09a833df5fde2418ea Mon Sep 17 00:00:00 2001 From: Adam Eehan Date: Sat, 7 Nov 2026 20:44:07 +0530 Subject: [PATCH] feat(newsletter): integrate Hostinger Reach automated subscription with serverless endpoint --- api/subscribe.js | 62 ++++++++++++++++++++++++++++ index.html | 103 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 api/subscribe.js diff --git a/api/subscribe.js b/api/subscribe.js new file mode 100644 index 0000000..b12eacd --- /dev/null +++ b/api/subscribe.js @@ -0,0 +1,62 @@ +// Vercel Serverless Function: Automated Hostinger Reach Subscription +// Engineered for Aira Group of Technology (airaaigroup.in) + +export default async function handler(req, res) { + // Set CORS headers + res.setHeader("Access-Control-Allow-Origin", "*"); + res.setHeader("Access-Control-Allow-Methods", "POST, OPTIONS"); + res.setHeader("Access-Control-Allow-Headers", "Content-Type"); + + if (req.method === "OPTIONS") { + return res.status(200).end(); + } + + if (req.method !== "POST") { + return res.status(405).json({ error: "Method not allowed. Use POST." }); + } + + try { + const { email, name } = req.body || {}; + + if (!email || !email.includes("@")) { + return res.status(400).json({ error: "Valid email address is required." }); + } + + const HOSTINGER_TOKEN = process.env.HOSTINGER_API_TOKEN || "QVeJgNyXciHezaw5fsjAJeTiEXJfBfd4FqwUifna8cfab21c"; + const PROFILE_UUID = "623e0772-031e-44fc-8a18-d225af88bad6"; + const REACH_URL = `https://developers.hostinger.com/api/reach/v1/profiles/${PROFILE_UUID}/contacts`; + + const payload = { + email: email.trim().toLowerCase(), + name: name ? name.trim() : null + }; + + const hostingerRes = await fetch(REACH_URL, { + method: "POST", + headers: { + "Authorization": `Bearer ${HOSTINGER_TOKEN}`, + "Content-Type": "application/json", + "User-Agent": "AiraGroup-Portal/1.0" + }, + body: JSON.stringify(payload) + }); + + const responseText = await hostingerRes.text(); + + if (!hostingerRes.ok) { + console.error("[Hostinger Reach Error]:", hostingerRes.status, responseText); + return res.status(hostingerRes.status).json({ + error: "Failed to sync subscription with Hostinger.", + details: responseText + }); + } + + return res.status(200).json({ + success: true, + message: "Subscription confirmed! Please check your email to verify your subscription." + }); + } catch (err) { + console.error("[Subscribe API Exception]:", err); + return res.status(500).json({ error: "Internal server error. Please try again later." }); + } +} diff --git a/index.html b/index.html index df06de1..bb7f498 100644 --- a/index.html +++ b/index.html @@ -1784,6 +1784,62 @@ + +
+
+
+ +
+
+ +
+
+ + Sovereign Engineering Dispatches +
+

+ Sovereign Engineering. Zero Dependency. +

+

+ Subscribe to receive verified release updates, technical architectural deep-dives on bare-metal kernels, private mesh cellular networks, and sovereign AI platforms directly from Founder Er. Adam Eehan. +

+ + +
+ + + +
+ + + + +

+ 🔒 We respect your privacy. Zero spam. 1-click unsubscribe anytime. Read our Privacy Policy. +

+
+
+
+
+