diff --git a/src/pages/Maps.jsx b/src/pages/Maps.jsx index 1634165..c2c2165 100644 --- a/src/pages/Maps.jsx +++ b/src/pages/Maps.jsx @@ -231,8 +231,8 @@ function Maps() { // 2. Click Empty Map (Create New) const handleMapCreate = async (latlng) => { - // Only Field Agents (employees) can create - if (user?.role !== 'FIELD_AGENT' && user?.role !== 'ADMIN') return; + // Field Agents, Admins, and Owners can create new map entries + if (!['FIELD_AGENT', 'ADMIN', 'OWNER'].includes(user?.role)) return; setSelectedPropertyId(null); setNewPropertyLocation({ lat: latlng.lat, lng: latlng.lng, address: '' }); diff --git a/vite.config.js b/vite.config.js index 1820849..b220fb8 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,8 +1,40 @@ import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' +/** + * Dev-only stub for /api/* requests. + * + * The files in /api are Vercel serverless functions — they run only on Vercel, + * not in the local Vite dev server. When the frontend polls an endpoint like + * /api/hail-status during local dev, Vite would otherwise resolve that URL to + * the on-disk api/*.js file and push it through its module-transform pipeline, + * which crashes on server-only imports such as `@vercel/kv`. + * + * This middleware intercepts /api/* before Vite transforms anything and returns + * a 503. Every frontend hook that hits these endpoints already degrades + * gracefully on a failed fetch (falls back to mock data / inactive storm state), + * so the app behaves correctly in local dev — just without the live API. + */ +const devApiStub = { + name: 'dev-api-stub', + apply: 'serve', + configureServer(server) { + server.middlewares.use((req, res, next) => { + if (req.url && req.url.startsWith('/api/')) { + res.statusCode = 503 + res.setHeader('Content-Type', 'application/json') + res.end(JSON.stringify({ + error: 'API routes run only on Vercel and are unavailable in local dev.', + })) + return + } + next() + }) + }, +} + export default defineConfig({ - plugins: [react()], + plugins: [react(), devApiStub], server: { // Don't watch or serve /api — those are Vercel serverless functions, not frontend code watch: { ignored: ['**/api/**'] },