mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 18:52:06 +00:00
Feat: Implement mapbox for geocoding and location data for brewery posts
This commit is contained in:
12
src/config/env/index.ts
vendored
12
src/config/env/index.ts
vendored
@@ -22,6 +22,7 @@ const envSchema = z.object({
|
||||
NODE_ENV: z.enum(['development', 'production', 'test']),
|
||||
SPARKPOST_API_KEY: z.string(),
|
||||
SPARKPOST_SENDER_ADDRESS: z.string().email(),
|
||||
MAPBOX_ACCESS_TOKEN: z.string()
|
||||
});
|
||||
|
||||
const parsed = envSchema.safeParse(env);
|
||||
@@ -145,3 +146,14 @@ export const SPARKPOST_API_KEY = parsed.data.SPARKPOST_API_KEY;
|
||||
* @see https://app.sparkpost.com/domains/list/sending
|
||||
*/
|
||||
export const SPARKPOST_SENDER_ADDRESS = parsed.data.SPARKPOST_SENDER_ADDRESS;
|
||||
|
||||
/**
|
||||
* Your Mapbox access token.
|
||||
*
|
||||
* @example
|
||||
* 'pk.abcdefghijklmnopqrstuvwxyz123456';
|
||||
*
|
||||
* @see https://docs.mapbox.com/help/how-mapbox-works/access-tokens/
|
||||
*/
|
||||
|
||||
export const MAPBOX_ACCESS_TOKEN = parsed.data.MAPBOX_ACCESS_TOKEN;
|
||||
12
src/config/mapbox/geocoder.ts
Normal file
12
src/config/mapbox/geocoder.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import mbxGeocoding from '@mapbox/mapbox-sdk/services/geocoding';
|
||||
|
||||
import { MAPBOX_ACCESS_TOKEN } from '../env';
|
||||
|
||||
const geocoder = mbxGeocoding({ accessToken: MAPBOX_ACCESS_TOKEN });
|
||||
|
||||
const geocode = async (query: string) => {
|
||||
const geoData = await geocoder.forwardGeocode({ query, limit: 1 }).send();
|
||||
return geoData.body.features[0];
|
||||
};
|
||||
|
||||
export default geocode;
|
||||
Reference in New Issue
Block a user