This project is a complete, deployable example of a Webflow Code Component powered by a backend API hosted on Webflow Cloud. It provides a full-featured "Store Locator" that can be dropped into any Webflow site, configured visually, and powered by your Webflow CMS data. See a live example here.
This repository contains two main parts:
-
A React-based Code Component (
/src/components/StoreLocator):- A reusable UI for finding and displaying store locations on a map.
- A Setup UI to configure backend API Requests
- The frontend UI is adapted for Webflow using
@webflow/reactinStoreLocator.webflow.tsx, allowing designers to configure it visually through props in the Designer. - Built with Leaflet for map rendering.
-
An Astro-based Backend API (
/src/pages/api):- Designed to be deployed seamlessly to Webflow Cloud.
- Provides secure, server-side access to your Webflow CMS data and Mapbox API keys.
- Features a simple setup UI to configure sites, collections, and generate a secure JWT for the frontend component.
The separation between the frontend component and the backend API ensures that sensitive information like your Webflow API Token and Mapbox API Key are never exposed to the browser.
- Setup: A user visits the deployed backend's
/setuppage, authenticates with Webflow, selects a site and CMS Collection, and enters their Mapbox key. - Token Generation: The setup page generates a JSON Web Token (JWT). This token contains the
siteId,collectionId, and the Mapbox key, signed securely by the server. - Component Configuration: The developer copies this JWT and pastes it into the component's
Auth Tokenprop in the Webflow Designer. TheAPI Base URLis also set to the deployed backend's URL. - Live Usage: When a visitor views the live site, the Store Locator component uses the JWT to make secure calls to the backend API. The backend validates the token and proxies requests to the Webflow CMS and Mapbox, returning only the necessary data.
Follow these steps to set up the backend on Webflow Cloud and publish the Code Component to your Webflow workspace.
- A Webflow account (Workspace plan required for Libraries).
- A GitHub account.
- A Mapbox account and a public access token.
- Node.js (v20.0.0 or higher).
- The Webflow CLI installed locally to your project:
npm install @webflow/webflow-cli
Clone this repository to your local machine and install the necessary npm packages.
git clone https://github.com/webflow-examples/store-locator.git
cd store-locator
npm installIn your Webflow site, create a new CMS Collection with the following details:
- Collection Name:
Locations - Collection Slug:
locations
Add the following fields to the collection. The slug field is the unique identifier used by the application.
| Field Name | Field Type | Required | Help Text |
|---|---|---|---|
Name |
Plain Text |
Yes | The name of the store or location |
Address |
Plain Text |
Yes | Full street address for geocoding |
Phone |
Phone Number |
No | Contact phone number |
Latitude |
Number |
No | Will be auto-generated |
Longitude |
Number |
No | Will be auto-generated |
Note: The
LatitudeandLongitudefields are optional. If an address is provided without coordinates, the backend will automatically geocode it using Mapbox and store the results.
Note: You can use the Webflow MCP Server to handle the CMS setup on your site. See details in the dropdown below.
Add MCP Server to your Client
### Cursor
```
{
"mcpServers": {
"webflow": {
"url": "https://mcp.webflow.com/sse"
}
}
}
```
### Claude Desktop
```
{
"mcpServers": {
"webflow": {
"command": "npx",
"args": ["mcp-remote", "https://mcp.webflow.com/sse"]
}
}
}
```
### Windsurf
```
{
"mcpServers": {
"webflow": {
"serverUrl": "https://mcp.webflow.com/sse"
}
}
}
```
This project uses a .dev.vars file for local development and Cloudflare secrets for production. Create a .dev.vars file in the root of your project by copying the example:
cp .dev.vars.example .dev.varsFill in the required values:
WEBFLOW_CLIENT_ID&WEBFLOW_CLIENT_SECRET: Get these by creating a new Webflow App under your Workspace settings. Set the Redirect URI to[YOUR_DEPLOYED_URL]/api/auth/oauth2/callback/webflow. Or tohttp://localhost:4321/api/auth/oauth2/callback/webflowif testing locally.BETTER_AUTH_SECRET: A long, random string you create to sign JWTs.PUBLIC_BETTER_AUTH_URL: The base URL where this app will be deployed (e.g.,https://my-site.webflow.io/map).
When you deploy to Webflow Cloud, you will need to add these as Secrets in your Webflow Cloud dashboard, which is linked from your Site Settings -> Webflow Cloud tab.
To run the project locally, you'll first neeed to set up your DB. Run the follwing command in your terminal
npm run db:apply:local
Then you can start the app:
npm run dev
See the component configuration section for more details.
Follow the official Webflow Cloud Getting Started Guide to deploy this application. The key steps are:
- Push the cloned repository to your own new GitHub repository.
- In your Webflow Site Settings, go to the Webflow Cloud tab.
- Create a New Project, link your GitHub repo, and create an Environment (e.g., from your
mainbranch). - Set the Mount Path (e.g.,
/map). This is the subpath where your app will live. - Configure your production secrets in the environment dashboard.
Once configured, Webflow Cloud will automatically deploy your application whenever you push to the connected branch.
Once your backend is deployed, navigate to its setup page (e.g., https://my-site.webflow.io/map/setup).
- Login with Webflow: Authenticate your account.
- Enter Mapbox Key: Paste your public Mapbox access token.
- Select Site & Collection: Choose the Webflow site and the
Locationscollection you created earlier. - Save & Generate Token: Click the button to save your settings and generate the JWT.
- Copy the Token: Copy the generated auth token. You will need it in the Webflow Designer.
Now, share the React component from your local machine to your Webflow workspace using the CLI.
npx webflow library shareThis command bundles the component defined in src/components/StoreLocator/StoreLocator.webflow.tsx and makes it available as a shared library in your Webflow workspace.
For more details, see the Code Components Documentation.
- Open your site in the Webflow Designer.
- Go to the Libraries panel and install the "Store Locator" library.
- Drag the Store Locator component from the Component Panel onto your canvas.
- With the component selected, go to the Settings Panel.
- Fill in the component props:
- API Base URL: The URL of your deployed backend (e.g.,
https://my-site.webflow.io/map). - Auth Token (JWT): Paste the token you generated in the setup UI.
- Map Style: Choose a default Mapbox style.
- Distance Unit: Choose Miles or Kilometers.
- API Base URL: The URL of your deployed backend (e.g.,
- Publish your site. Your Store Locator should now be live!
src/components/StoreLocator/StoreLocator.tsx: The core React component logic.src/components/StoreLocator/StoreLocator.webflow.tsx: The Webflow declaration file that defines the component's props.src/pages/api/locations.ts: The secure API endpoint that fetches CMS items.src/pages/api/geocode.ts: The API endpoint for geocoding addresses via Mapbox.src/pages/api/auth/generate-token.ts: The endpoint that creates the secure JWT for the component.src/middleware.ts: Handles CORS and JWT validation for protected API routes.src/lib/auth.ts: Server-side authentication configuration usingbetter-auth.drizzle.config.ts&src/lib/db/schema.ts: Database schema and configuration for D1.