Skip to content

Commit 4cbc64e

Browse files
committed
Dev: make mapbox config items optional
To make development against a local bikehopper-web-app easier, this makes mapboxStyleUrl in the API-returned config completely optional in dev mode, and makes both mapboxStyleUrl and mapboxAccessToken optional if values are defined in env vars provided to bikehopper-ui. (This will become moot after the mergening)
1 parent 74cce3b commit 4cbc64e

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

src/lib/region.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,22 @@ export function getMapboxStyleParams(): {
5959
mapboxAccessToken = import.meta.env.VITE_MAPBOX_TOKEN;
6060
}
6161

62+
if (!mapboxAccessToken) {
63+
throw new Error(
64+
'mapboxAccessToken must be defined either in env var or config',
65+
);
66+
}
67+
68+
if (!mapboxStyleUrl) {
69+
if (import.meta.env.DEV) {
70+
mapboxStyleUrl = 'mapbox://styles/mapbox/streets-v11';
71+
} else {
72+
throw new Error(
73+
'in production, mapboxStyleUrl must be defined either in env var or config',
74+
);
75+
}
76+
}
77+
6278
return { mapboxAccessToken, mapboxStyleUrl };
6379
}
6480

@@ -85,8 +101,8 @@ export const RegionConfigSchema = z.object({
85101
.tuple([Longitude, Latitude, Longitude, Latitude])
86102
.optional(),
87103
supportedRegionDescription: z.string().optional(),
88-
mapboxAccessToken: z.string(),
89-
mapboxStyleUrl: z.string(),
104+
mapboxAccessToken: z.string().optional(),
105+
mapboxStyleUrl: z.string().optional(),
90106
});
91107
export type RegionConfig = z.infer<typeof RegionConfigSchema>;
92108

0 commit comments

Comments
 (0)