A real-time, location-aware directory and map of New York City's public restrooms, built with React, Vite, Leaflet, and Cloudflare Pages.
This application consumes live data from the NYC Open Data Portal via the Socrata API and processes operating hours to provide an "Open Now" heuristic.
- Geolocation & Proximal Search: Uses
navigator.geolocationor the free Nominatim OpenStreetMap API to find the closest bathrooms within a 1.5-mile radius of a user's location or searched address. - Operating Hours Engine: Parses and translates complex municipal operating hours (e.g., "Dawn to dusk" or "8:00 AM - 4:00 PM") into real-time operational heuristics (Open, Maybe Open, Closed).
- Theme Switcher: Fully functional CSS-variable driven theme engine holding the Default (Dark) theme, an NYC Open Data (Light) theme, and a WeGovNYC (Light) theme.
- Dynamic Maps: Integrated
react-leafletmapping with responsive TileLayers that switch between CartoDB Dark Matter and Positron based on the active theme. - API Proxy: Uses a Cloudflare Pages Function proxy (
functions/api/restrooms.js) to cache Socrata upstream data at the edge, drastically speeding up initial loads.
You need Node.js (v18+) and npm installed.
# Clone the repository
git clone https://github.com/wegovnyc/bathroom-demo.git
cd bathroom-demo
# Install dependencies
npm installBecause the application relies on Cloudflare Pages Functions for its API proxy, you must run it using the wrangler CLI to simulate the edge proxy.
# Start the Vite server wrapped in the Wrangler edge proxy
npx wrangler pages dev -- npm run devThe app will become available at http://localhost:8788.
Deploying this application to Cloudflare Pages is completely free and requires zero API keys.
- Push to GitHub: Make sure this code is pushed to your GitHub account.
- Connect to Cloudflare:
- Log into the Cloudflare Dashboard
- Go to Workers & Pages -> Create Application -> Pages -> Connect to Git
- Select this repository.
- Build Settings:
- Framework Preset:
ReactorVite - Build Command:
npm run build - Build Output Directory:
dist
- Framework Preset:
- Deploy: Click Save and Deploy. Cloudflare will automatically build the site, deploy the backend
functions/api/restrooms.jsedge worker, and assign you a.pages.devURL.
This application intentionally does NOT use any proprietary map providers that require API keys (e.g., Google Maps, Mapbox).
- Basemaps: Provided by CartoDB (free tier).
- Geocoding: Handled by Nominatim API (OpenStreetMap), restricted via strict viewbox bounding to the 5 boroughs of NYC.
- Privacy: The application does not store user location data. The browser Geolocation API is processed entirely on the client side.