UNPKG

rui-weather-service-api

Version:

Weather API service with OpenWeatherMap integration - includes both standalone API and MCP server

45 lines 1.37 kB
import dotenv from 'dotenv'; // Load environment variables from .env file dotenv.config(); // Default configuration values const defaultConfig = { baseUrl: 'https://api.openweathermap.org/data/2.5', units: 'metric', language: 'en', timeout: 10000, maxRetries: 3, rejectUnauthorized: false // Note: In production, this should be true }; // Current configuration (combining defaults with environment variables) const config = { ...defaultConfig, apiKey: process.env.WEATHER_API_KEY || '' }; /** * Updates the configuration with the provided options * @param options Configuration options to update */ export function updateConfig(options) { Object.assign(config, options); // Update environment variable if apiKey is provided if (options.apiKey) { process.env.WEATHER_API_KEY = options.apiKey; } } /** * Returns the current configuration */ export function getConfig() { return { ...config }; // Return a copy to prevent mutations } /** * Validates that the configuration has the required fields * @throws Error if configuration is invalid */ export function validateConfig() { if (!config.apiKey) { throw new Error('API key is not configured. Please set WEATHER_API_KEY environment variable or provide apiKey in options.'); } } export default config; //# sourceMappingURL=index.js.map