This is a simple weather application that provides real-time weather data for any city. The application is built using HTML, CSS, and JavaScript for the frontend, with a serverless function backend deployed on Cloudflare Pages.
- public/: Contains the frontend assets (HTML, CSS, and JavaScript).
- functions/api/: Contains the serverless function that fetches weather data from an external API.
- .dev.vars: Local environment variables file for Wrangler.
- .dev.vars.example: An example file for the required environment variables.
-
Clone the repository:
git clone <repository-url> cd <repository-directory>
-
Install dependencies:
This project uses Wrangler to run locally and deploy. Make sure you have it installed and configured.
-
Set up environment variables:
Create a .dev.vars file in the root of the project and add your weather API key:
WEATHER_API_KEY=your_weather_api_keyYou can get a free API key from a provider like OpenWeatherMap.
To run the application locally, use the following Wrangler command:
wrangler pages dev publicTo deploy the application to Cloudflare Pages, follow these steps:
-
Deploy the application:
Run the following Wrangler command to deploy your project:
wrangler pages deploy public
-
Configure environment variables:
After deploying, you need to add the
WEATHER_API_KEYto your Cloudflare Pages project.- Go to your Cloudflare dashboard.
- Navigate to Workers & Pages and select your project.
- Go to Settings > Environment variables.
- Add a new variable with the name
WEATHER_API_KEYand your API key as the value.