Goal: API endpoint to get static images of maps.
- Mapbox static images service | 50K requests/mo free but then $1/1,000 requests (maybe caching makes this scale better but unclear what their caching policy is)
- Headless Leaflet | Running node-canvas requires installing deps that requires I set up containers (was looking for something I could run in a lambda function)
- Render the map in a browser, setting map properties through url parameters (
public/index.html
) - Launch with Puppeteer and return a screenshot (
api/screenshot.js
)
Note: this is using browserless.io which is paid but is quicker to run puppeteer (can make that cheaper later), and I can permanently cache the images unlike Mapbox.
- Needs
.env
file:
BROWSERLESSTOKEN=xxx
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
(see _db.js for Firebase env vars required)
npm run i
vercel