@hivetechs/hive-ai
Version:
Real-time streaming AI consensus platform with HTTP+SSE MCP integration for Claude Code, VS Code, Cursor, and Windsurf - powered by OpenRouter's unified API
73 lines (72 loc) • 2.38 kB
JavaScript
/**
* Configurable API Endpoints
*
* Security: Removes hardcoded domains to prevent infrastructure targeting
* Allows runtime configuration of API endpoints for different environments
*/
// Default configuration with fallback domains
const DEFAULT_ENDPOINTS = {
apiEndpoint: process.env.HIVE_API_ENDPOINT || 'https://gateway.hivetechs.io',
subscriptionEndpoint: process.env.HIVE_SUBSCRIPTION_ENDPOINT || 'https://gateway.hivetechs.io/verify-subscription',
usageEndpoint: process.env.HIVE_USAGE_ENDPOINT || 'https://gateway.hivetechs.io/sync-usage',
checkoutEndpoint: process.env.HIVE_CHECKOUT_ENDPOINT || 'https://gateway.hivetechs.io/create-checkout',
allowedDomains: [
'gateway.hivetechs.io',
'api.hivetechs.io', // Legacy support
'hive-api.hivetechs.io', // Legacy support
'api.openai.com',
'api.anthropic.com',
'generativelanguage.googleapis.com',
'api.x.ai'
]
};
// Runtime configuration
let currentConfig = { ...DEFAULT_ENDPOINTS };
/**
* Get current endpoint configuration
*/
export function getEndpointConfig() {
return { ...currentConfig };
}
/**
* Update endpoint configuration (for testing/staging environments)
*/
export function updateEndpointConfig(config) {
currentConfig = {
...currentConfig,
...config
};
}
/**
* Validate if a domain is allowed for API requests
*/
export function isAllowedDomain(domain) {
const config = getEndpointConfig();
return config.allowedDomains.some(allowed => domain === allowed || domain.endsWith('.' + allowed));
}
/**
* Get API endpoint for specific service
*/
export function getApiEndpoint(service = 'general') {
const config = getEndpointConfig();
switch (service) {
case 'subscription':
return config.subscriptionEndpoint;
case 'usage':
return config.usageEndpoint;
case 'checkout':
return config.checkoutEndpoint;
default:
return config.apiEndpoint;
}
}
/**
* Build full API URL for a specific endpoint
*/
export function buildApiUrl(path, service = 'general') {
const baseUrl = getApiEndpoint(service);
const cleanPath = path.startsWith('/') ? path : `/${path}`;
return `${baseUrl}${cleanPath}`;
}
// Export default configuration for backwards compatibility
export { DEFAULT_ENDPOINTS };