Rocky_Mountain_Vending/app/api/request-indexing/route.ts

97 lines
2.6 KiB
TypeScript

import { NextRequest, NextResponse } from "next/server"
import { getGSCConfig } from "@/lib/google-search-console"
// API routes are not supported in static export (GHL hosting)
export const dynamic = "force-static"
/**
* API Route for requesting URL indexing in Google Search Console
* POST /api/request-indexing
*
* Body: { url: 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 { url } = body
if (!url) {
return NextResponse.json(
{
success: false,
error: "URL is required",
},
{ status: 400 }
)
}
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
// 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 indexing requests, you would use:
// const { google } = require('googleapis');
// const searchconsole = google.searchconsole('v1');
// await searchconsole.urlInspection.index.inspect({
// requestBody: {
// inspectionUrl: url,
// siteUrl: config.siteUrl
// },
// auth: jwtClient
// });
return NextResponse.json({
success: true,
message: "Indexing request endpoint ready",
url,
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()
return NextResponse.json({
message: "Google Search Console URL Indexing Request API",
configured: !!(config.serviceAccountEmail && config.privateKey),
instructions:
"POST to this endpoint with { url: 'https://example.com/page' } in body",
})
}