Skip to Content
Technical GuideFrontend Route Handlers

Frontend Route Handlers

Source review: e30dd9b47, 2026-11-02. These are Next.js handlers inside the frontend, not the proxy backend’s /api contract. A relative browser request to /api/schools reaches this application; APISearch reaches NEXT_PUBLIC_API_URL + /api/listings/search. See API Services.

Shared boundary

src/app/api/_lib.ts provides assertSameOrigin, parseQuery, parseBody and getClientIp. assertSameOrigin checks whether the Referer starts with the configured application domain; an unset domain disables this check. It is not a JWT or resource-ownership check. Only handlers that call it get that behavior. Joi parsing returns validation errors; each handler still owns its upstream and failure response. Do not infer a common error envelope from the /api prefix.

Operation register

Each path maps directly to src/app/api/<path>/route.ts; bracket segments are dynamic. There are 23 handler files and 25 method exports in this register. “Origin” below means the shared Referer check, not authenticated access.

Path under /apiMethods and inputBoundary / ownerResult and failure behavior
agent-directoryGETOrigin; MoveSmartlyDirectory JSON; upstream failure 500
agent-reviewsGET query; POST review bodyOrigin; Joi review schemas; MoveSmartlyReviews / created review; POST revalidates /reviews and /about; failure 500
agent-reviews/summaryGET summary queryOrigin; Joi; MoveSmartlySummary; failure 500
agents/can-reviewGETOrigin; MoveSmartlyReview eligibility records; failure 500
blog/postsGET pagination, tag/categoryCMS blog client{ posts }; failure 500
careerGETOrigin; MoveSmartlyCareers with sanitized rendered content; failure 500
condo-developmentGET map polygonOrigin; bounds parser; MoveSmartlyDevelopments; invalid map 400, upstream 503
fetchMetaGET urlHandler fetches supplied URL; no shared origin checkHTML response; absent URL 400, failure 503
generateLocationsGET token, optional output=fileLOCATIONS_REGEN_TOKEN; LocationsTreeDownload or streamed progress; disabled 503, unauthorized 401; generation errors are JSON 500 or stream error records
listing-enrichmentGET mlsNumberMOVESMARTLY_API_URL; identifier allowlistDisabled 404, invalid identifier 400; enriched data from service
mapbox/poisGET Searchbox inputsOrigin; local parser, cache and Searchbox servicePOI results; validation, configuration, cancellation and upstream errors have separate branches
og/mapGET lat, lng, z, msMap image handlerImage; invalid input 400, upstream failure 503
overlay-locationsGET type/source, coordinates/radius, marker/boundary optionsAPILocations and GeoJSON conversionFeature collection; invalid input 400, failure 500 with empty collection
parcelGET map, zoomOrigin; parcel serviceGeometry simplified for zoom; invalid input 400, upstream 503
placesGET idOrigin; Google PlacesPlace details; absent id 400; upstream/not-found/authorization failures retained by handler
plans-surveysGET lat, lngPYB_API_URL; finite coordinate rangesDisabled 404, invalid input 400; service result otherwise
public-recordGET map and record filtersOrigin; typed query validation; APILocationsGeoJSON; invalid input 400, failure 500
revalidateGET query or POST JSON { path, token }REVALIDATE_TOKEN; safe path validationGET redirects, POST reports paths; disabled 503, unauthorized 401, invalid body/path 400
schoolsGET map, source, filters, zoom/boundariesOrigin; bounds and school helpersSchools filtered locally; invalid map 400, upstream 503
schools/coordsGET coordinate searchOrigin; school helpersCoordinate lookup; invalid input 400, upstream 503
schools/[id]GET numeric id and sourceOrigin; 1–10 digit identifierSchool detail without internal bbox fields; invalid 400, absent 404, upstream 503
social-housingGET map polygonOrigin; bounds parser; MoveSmartlyHousing records; invalid map 400, upstream 503
streetViewGET estimateId or ulid, optional sizeAPIEstimate then Street View imageSuccessful image cached for 86400 seconds; failures return fallback image with error status

The endpoint-specific absence of a guard is a description of the current code, not permission to expose arbitrary new inputs. New handlers should reuse the nearest equivalent contract, including the map polygon format. External values entering URL path segments require an explicit allowlist before interpolation.

Revalidation contract

POST accepts a JSON object with path and token. The path must start with /, exclude .., match the handler’s safe-character expression and fit its 300-character limit. The handler expands the input against rewrites.generated.json in both source-to-destination and destination-to-source directions, then calls revalidatePath for the deduplicated paths. A success response records invalidation; it does not prove fresh upstream content has rendered. See Caching and Revalidation.

Other route handlers

The other six route.ts files publish crawl surfaces: robots.txt, sitemap.xml, sitemap-content.xml, listing/sitemap-index.xml, listing/sitemap/[id], and documentation/sitemap/[site]. They belong to SEO, not the interactive JSON API. The six metadata sitemap.ts files are separate from this 29-file handler inventory.

Evidence and limits

This register was reconciled against handler exports and shared helpers. It is source evidence, not an HTTP replay of each integration. Credentials, deployment URLs and tenant records are intentionally absent. Mutation endpoints were not called while writing documentation.

Last updated on