Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: Add missing API routes in `www` that were accidentally deleted (#37857)

Ivan Vasilovcf24d05d73d7
diff --git a/apps/www/app/api-v2/opt-out/[ref]/route.ts b/apps/www/app/api-v2/opt-out/[ref]/route.ts
new file mode 100644
index 00000000000..9028a6934b2
--- /dev/null
+++ b/apps/www/app/api-v2/opt-out/[ref]/route.ts
@@ -0,0 +1,102 @@
+import { NextRequest, NextResponse } from 'next/server'
+import { createClient } from '@supabase/supabase-js'
+
+const supabaseUrl = process.env.NEXT_PUBLIC_EMAIL_ABUSE_URL as string
+const supabaseServiceKey = process.env.EMAIL_ABUSE_SERVICE_KEY as string
+const hcaptchaSecret = process.env.HCAPTCHA_SECRET_KEY as string
+
+// Function to verify hCaptcha token
+async function verifyCaptcha(token: string): Promise<boolean> {
+ try {
+ const response = await fetch('https://api.hcaptcha.com/siteverify', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/x-www-form-urlencoded',
+ },
+ body: new URLSearchParams({
+ secret: hcaptchaSecret,
+ response: token,
+ }),
+ })
+
+ const data = await response.json()
+ return data.success === true
+ } catch (error) {
+ console.error('Error verifying captcha:', error)
+ return false
+ }
+}
+
+export async function POST(req: NextRequest, props: { params: Promise<{ ref: string }> }) {
+ const params = await props.params
+ const ref = params.ref
+ const { reason, email, captchaToken } = await req.json()
+
+ // Validate reason
+ const allowedReasons = ['phishing', 'advertisement', 'malware', 'scam', 'other']
+ if (!allowedReasons.includes(reason)) {
+ return NextResponse.json({ error: 'Bad Request: Invalid reason provided.' }, { status: 400 })
+ }
+
+ const supabase = createClient(supabaseUrl, supabaseServiceKey)
+
+ if (!ref) {
+ return NextResponse.json(
+ { error: 'Bad Request: Missing or invalid project reference.' },
+ { status: 400 }
+ )
+ }
+
+ const refPattern = /^[a-zA-Z]{20}$/
+ const refIsInvalid = !refPattern.test(ref)
+
+ if (refIsInvalid) {
+ return NextResponse.json(
+ { error: 'Bad Request: Missing or invalid project reference.' },
+ { status: 400 }
+ )
+ }
+
+ // Verify captcha token
+ if (!captchaToken) {
+ return NextResponse.json(
+ { error: 'Bad Request: Missing captcha verification.' },
+ { status: 400 }
+ )
+ }
+
+ const isValidCaptcha = await verifyCaptcha(captchaToken)
+ if (!isValidCaptcha) {
+ return NextResponse.json(
+ { error: 'Bad Request: Invalid captcha verification.' },
+ { status: 400 }
+ )
+ }
+
+ try {
+ const { error: supabaseError } = await supabase
+ .from('manual_reports')
+ .insert([{ project_ref: ref, reason, email }])
+
+ if (supabaseError) throw new Error(`Supabase error: ${supabaseError.message}`)
+
+ const response = await fetch(process.env.EMAIL_REPORT_SLACK_WEBHOOK as string, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ text: `New report from: ${ref} \n\n ${reason}` }),
+ })
+
+ if (!response.ok) throw new Error('Failed to send to Slack')
+
+ return NextResponse.json(
+ { message: 'Thank you! We have received your report.' },
+ { status: 200 }
+ )
+ } catch (error) {
+ const errorMessage = (error as Error).message
+ return NextResponse.json(
+ { error: `Failure: Could not send post to Slack. Error: ${errorMessage}` },
+ { status: 500 }
+ )
+ }
+}
diff --git a/apps/www/app/api-v2/submit-form-contact-sales/route.tsx b/apps/www/app/api-v2/submit-form-contact-sales/route.tsx
new file mode 100644
index 00000000000..4f2e1aed08e
--- /dev/null
+++ b/apps/www/app/api-v2/submit-form-contact-sales/route.tsx
@@ -0,0 +1,111 @@
+const corsHeaders = {
+ 'Access-Control-Allow-Origin': '*',
+ 'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
+}
+
+const personalEmailDomains = [
+ '@gmail.com',
+ '@yahoo.com',
+ '@hotmail.',
+ '@outlook.com',
+ '@aol.com',
+ '@icloud.com',
+ '@live.com',
+ '@protonmail.com',
+ '@mail.com',
+ '@example.com',
+]
+
+const isValidEmail = (email: string): boolean => {
+ const emailPattern = /^[\w-\.+]+@([\w-]+\.)+[\w-]{2,8}$/
+ return emailPattern.test(email)
+}
+
+const isCompanyEmail = (email: string): boolean => {
+ for (const domain of personalEmailDomains) {
+ if (email.includes(domain)) {
+ return false
+ }
+ }
+
+ return true
+}
+
+export async function POST(req: Request) {
+ const HUBSPOT_PORTAL_ID = process.env.HUBSPOT_PORTAL_ID
+ const HUBSPOT_FORM_GUID = process.env.HUBSPOT_ENTERPRISE_FORM_GUID
+
+ const body = await req.json()
+ const { firstName, secondName, companyEmail, message } = body
+
+ if (!firstName || !secondName || !companyEmail || !message) {
+ return new Response(JSON.stringify({ message: 'All fields are required' }), {
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
+ status: 422,
+ })
+ }
+
+ // Validate email
+ if (companyEmail && !isValidEmail(companyEmail)) {
+ return new Response(JSON.stringify({ message: 'Invalid email address' }), {
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
+ status: 422,
+ })
+ }
+
+ // Validate company email
+ if (companyEmail && !isCompanyEmail(companyEmail)) {
+ return new Response(JSON.stringify({ message: 'Please use a company email address' }), {
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
+ status: 422,
+ })
+ }
+
+ try {
+ const response = await fetch(
+ `https://api.hsforms.com/submissions/v3/integration/submit/${HUBSPOT_PORTAL_ID}/${HUBSPOT_FORM_GUID}`,
+ {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({
+ fields: [
+ { objectTypeId: '0-1', name: 'firstname', value: firstName },
+ { objectTypeId: '0-1', name: 'lastname', value: secondName },
+ { objectTypeId: '0-1', name: 'email', value: companyEmail },
+ { objectTypeId: '0-1', name: 'message', value: message },
+ ],
+ context: {
+ pageUri: 'https://supabase.com/contact/sales',
+ pageName: 'Enterprise Demo Request Form',
+ },
+ legalConsentOptions: {
+ consent: {
+ consentToProcess: true,
+ text: 'By submitting this form, I confirm that I have read and understood the Privacy Policy.',
+ },
+ },
+ }),
+ }
+ )
+
+ if (!response.ok) {
+ const errorData = await response.json()
+ return new Response(JSON.stringify({ message: errorData.message }), {
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
+ status: response.status,
+ })
+ }
+
+ return new Response(JSON.stringify({ message: 'Submission successful' }), {
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
+ status: 200,
+ })
+ } catch (error: any) {
+ return new Response(JSON.stringify({ error: error.message }), {
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
+ status: 500,
+ })
+ }
+}
diff --git a/apps/www/app/api-v2/submit-form-sos2025-newsletter/route.tsx b/apps/www/app/api-v2/submit-form-sos2025-newsletter/route.tsx
new file mode 100644
index 00000000000..856845ad620
--- /dev/null
+++ b/apps/www/app/api-v2/submit-form-sos2025-newsletter/route.tsx
@@ -0,0 +1,75 @@
+const corsHeaders = {
+ 'Access-Control-Allow-Origin': '*',
+ 'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
+}
+
+const isValidEmail = (email: string): boolean => {
+ const emailPattern = /^[\w-\.+]+@([\w-]+\.)+[\w-]{2,8}$/
+ return emailPattern.test(email)
+}
+
+export async function POST(req: Request) {
+ const HUBSPOT_PORTAL_ID = process.env.HUBSPOT_PORTAL_ID
+ const HUBSPOT_FORM_GUID = '721fc4aa-13eb-4c25-91be-4fe9b530bed1'
+
+ const body = await req.json()
+ const { email } = body
+
+ if (!email) {
+ return new Response(JSON.stringify({ message: 'All fields are required' }), {
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
+ status: 422,
+ })
+ }
+
+ // Validate email
+ if (email && !isValidEmail(email)) {
+ return new Response(JSON.stringify({ message: 'Invalid email address' }), {
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
+ status: 422,
+ })
+ }
+
+ try {
+ const response = await fetch(
+ `https://api.hsforms.com/submissions/v3/integration/submit/${HUBSPOT_PORTAL_ID}/${HUBSPOT_FORM_GUID}`,
+ {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({
+ fields: [{ objectTypeId: '0-1', name: 'email', value: email }],
+ context: {
+ pageUri: 'https://supabase.com/state-of-startups',
+ pageName: 'State of Startups 2025',
+ },
+ legalConsentOptions: {
+ consent: {
+ consentToProcess: true,
+ text: 'By submitting this form, I confirm that I have read and understood the Privacy Policy.',
+ },
+ },
+ }),
+ }
+ )
+
+ if (!response.ok) {
+ const errorData = await response.json()
+ return new Response(JSON.stringify({ message: errorData.message }), {
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
+ status: response.status,
+ })
+ }
+
+ return new Response(JSON.stringify({ message: 'Submission successful' }), {
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
+ status: 200,
+ })
+ } catch (error: any) {
+ return new Response(JSON.stringify({ error: error.message }), {
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
+ status: 500,
+ })
+ }
+}
diff --git a/apps/www/app/api-v2/submit-form-talk-to-partnership/route.tsx b/apps/www/app/api-v2/submit-form-talk-to-partnership/route.tsx
new file mode 100644
index 00000000000..b41b9064300
--- /dev/null
+++ b/apps/www/app/api-v2/submit-form-talk-to-partnership/route.tsx
@@ -0,0 +1,110 @@
+const corsHeaders = {
+ 'Access-Control-Allow-Origin': '*',
+ 'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
+}
+
+const personalEmailDomains = [
+ '@gmail.com',
+ '@yahoo.com',
+ '@hotmail.',
+ '@outlook.com',
+ '@aol.com',
+ '@icloud.com',
+ '@live.com',
+ '@protonmail.com',
+ '@mail.com',
+ '@example.com',
+]
+
+const isValidEmail = (email: string): boolean => {
+ const emailPattern = /^[\w-\.+]+@([\w-]+\.)+[\w-]{2,8}$/
+ return emailPattern.test(email)
+}
+
+const isCompanyEmail = (email: string): boolean => {
+ for (const domain of personalEmailDomains) {
+ if (email.includes(domain)) {
+ return false
+ }
+ }
+
+ return true
+}
+
+export async function POST(req: Request) {
+ const HUBSPOT_PORTAL_ID = process.env.HUBSPOT_PORTAL_ID
+ const HUBSPOT_FORM_GUID = process.env.HUBSPOT_PARTNERSHIP_FORM_GUID
+
+ const body = await req.json()
+ const { firstName, secondName, companyEmail } = body
+
+ if (!firstName || !secondName || !companyEmail) {
+ return new Response(JSON.stringify({ message: 'All fields are required' }), {
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
+ status: 422,
+ })
+ }
+
+ // Validate email
+ if (companyEmail && !isValidEmail(companyEmail)) {
+ return new Response(JSON.stringify({ message: 'Invalid email address' }), {
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
+ status: 422,
+ })
+ }
+
+ // Validate company email
+ if (companyEmail && !isCompanyEmail(companyEmail)) {
+ return new Response(JSON.stringify({ message: 'Please use a company email address' }), {
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
+ status: 422,
+ })
+ }
+
+ try {
+ const response = await fetch(
+ `https://api.hsforms.com/submissions/v3/integration/submit/${HUBSPOT_PORTAL_ID}/${HUBSPOT_FORM_GUID}`,
+ {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({
+ fields: [
+ { objectTypeId: '0-1', name: 'firstname', value: firstName },
+ { objectTypeId: '0-1', name: 'lastname', value: secondName },
+ { objectTypeId: '0-1', name: 'email', value: companyEmail },
+ ],
+ context: {
+ pageUri: 'https://supabase.com/solutions/ai-builders',
+ pageName: 'Solutions / AI Builders',
+ },
+ legalConsentOptions: {
+ consent: {
+ consentToProcess: true,
+ text: 'By submitting this form, I confirm that I have read and understood the Privacy Policy.',
+ },
+ },
+ }),
+ }
+ )
+
+ if (!response.ok) {
+ const errorData = await response.json()
+ return new Response(JSON.stringify({ message: errorData.message }), {
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
+ status: response.status,
+ })
+ }
+
+ return new Response(JSON.stringify({ message: 'Submission successful' }), {
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
+ status: 200,
+ })
+ } catch (error: any) {
+ return new Response(JSON.stringify({ error: error.message }), {
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
+ status: 500,
+ })
+ }
+}