92 lines
2.8 KiB
TypeScript
92 lines
2.8 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server"
|
|
import { getGSCConfig } from "@/lib/google-search-console"
|
|
import { businessConfig } from "@/lib/seo-config"
|
|
|
|
// API routes are not supported in static export (GHL hosting)
|
|
export const dynamic = "force-static"
|
|
|
|
/**
|
|
* API Route for submitting sitemap to Google Search Console
|
|
* POST /api/sitemap-submit
|
|
*
|
|
* Body: { sitemapUrl?: string, siteUrl?: string }
|
|
* NOTE: This route is disabled for static export.
|
|
*/
|
|
|
|
// Required for static export - returns empty array to skip this route
|
|
export async function generateStaticParams() {
|
|
return []
|
|
}
|
|
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
const body = await request.json()
|
|
const sitemapUrl =
|
|
body.sitemapUrl || `${businessConfig.website}/sitemap.xml`
|
|
const siteUrl = body.siteUrl || businessConfig.website
|
|
|
|
const config = getGSCConfig()
|
|
|
|
if (!config.serviceAccountEmail || !config.privateKey) {
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
error: "Google Search Console credentials not configured",
|
|
message:
|
|
"Please set GOOGLE_SERVICE_ACCOUNT_EMAIL and GOOGLE_PRIVATE_KEY environment variables",
|
|
},
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
|
|
// Note: This is a placeholder implementation
|
|
// In production, you would use the Google Search Console API
|
|
// For now, we'll return instructions for manual submission
|
|
// The actual API integration requires:
|
|
// 1. Google Cloud project with Search Console API enabled
|
|
// 2. Service account with proper permissions
|
|
// 3. OAuth2 authentication setup
|
|
|
|
// For automated submission, you would use:
|
|
// const { google } = require('googleapis');
|
|
// const searchconsole = google.searchconsole('v1');
|
|
// await searchconsole.sitemaps.submit({
|
|
// siteUrl: siteUrl,
|
|
// feedpath: sitemapUrl,
|
|
// auth: jwtClient
|
|
// });
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
message: "Sitemap submission endpoint ready",
|
|
sitemapUrl,
|
|
siteUrl,
|
|
note: "See docs/operations/SEO_SETUP.md for complete Google Search Console API setup instructions",
|
|
})
|
|
} catch (error) {
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
error:
|
|
error instanceof Error ? error.message : "Unknown error occurred",
|
|
},
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* GET endpoint for testing
|
|
*/
|
|
export async function GET() {
|
|
const config = getGSCConfig()
|
|
const sitemapUrl = `${businessConfig.website}/sitemap.xml`
|
|
|
|
return NextResponse.json({
|
|
message: "Google Search Console Sitemap Submission API",
|
|
sitemapUrl,
|
|
configured: !!(config.serviceAccountEmail && config.privateKey),
|
|
instructions:
|
|
"POST to this endpoint with optional sitemapUrl and siteUrl in body",
|
|
})
|
|
}
|