Network & CORS Issues
Solutions for connectivity problems, CORS errors, and network-related issues.
CORS Errors
Symptoms
- Browser console shows CORS errors
- "Access-Control-Allow-Origin" errors
- Requests blocked by browser
- Works in Node.js but not browser
Understanding CORS
CORS (Cross-Origin Resource Sharing) is a browser security feature. It only affects browser-based applications, not server-side code.
Solutions
1. Verify You're Using the Right Endpoint
Toggly provides different endpoints:
// ✅ For browser/client-side apps (definitions worker, CORS-enabled)
const toggly = new TogglyClient({
appKey: 'your-key',
environment: 'production',
baseURL: 'https://definitions.toggly.io'
});
// ✅ For server-side apps (same host; CORS not required)
const toggly = new TogglyClient({
appKey: 'your-key',
environment: 'production',
baseURL: 'https://definitions.toggly.io'
});
2. Use Client-Side SDK
For browser apps, always use the client-side SDK:
@ops-ai/feature-flags-togglyfor vanilla JS@ops-ai/react-feature-flags-togglyfor React@ops-ai/ngx-feature-flags-togglyfor Angular@ops-ai/vue-feature-flags-togglyfor Vue
These SDKs are pre-configured with the correct endpoints.
3. Proxy Requests (If Needed)
For SSR frameworks like Next.js or Nuxt:
// api/toggly-proxy.ts
export default async function handler(req, res) {
const response = await fetch('https://definitions.toggly.io/evaluated-signed/...', {
headers: {
'Authorization': `Bearer ${process.env.TOGGLY_API_KEY}`
}
});
const data = await response.json();
res.json(data);
}
Network Timeout
Symptoms
- Requests take too long
- "Network timeout" errors
- SDK initialization hangs
- Intermittent connectivity
Solutions
1. Increase Timeout
const toggly = new TogglyClient({
appKey: 'your-key',
environment: 'production',
timeout: 10000, // 10 seconds (default is 5s)
});
2. Check Network Connectivity
# Test connectivity to Toggly
curl -I https://definitions.toggly.io
# Check DNS resolution
nslookup definitions.toggly.io
3. Verify Firewall/Proxy
Corporate firewalls may block requests:
- Check with IT department
- Whitelist
*.toggly.iodomains - Configure proxy settings if required
// Configure proxy (Node.js)
const toggly = new TogglyClient({
appKey: 'your-key',
environment: 'production',
proxy: {
host: 'proxy.company.com',
port: 8080,
}
});
SSL/TLS Errors
Symptoms
- "SSL certificate verification failed"
- "CERT_HAS_EXPIRED" errors
- "unable to verify the first certificate"
Solutions
1. Update Node.js/Runtime
Older versions may have outdated SSL certificates:
# Check Node.js version
node --version
# Update to latest LTS
nvm install --lts
nvm use --lts
2. Update CA Certificates
# Ubuntu/Debian
sudo apt-get update
sudo apt-get install ca-certificates
# macOS
brew install ca-certificates
3. Check System Time
Incorrect system time can cause SSL errors:
# Verify system time is correct
date
# Update if needed (varies by OS)
DNS Resolution Issues
Symptoms
- "getaddrinfo ENOTFOUND" errors
- Can't resolve toggly.io domains
- Works on one network but not another
Solutions
1. Verify DNS
# Test DNS resolution
nslookup definitions.toggly.io
nslookup api.toggly.io
# Try different DNS server
nslookup definitions.toggly.io 8.8.8.8
2. Clear DNS Cache
# macOS
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder
# Windows
ipconfig /flushdns
# Linux
sudo systemd-resolve --flush-caches
3. Configure DNS Server
Update network settings to use reliable DNS:
- Google DNS: 8.8.8.8, 8.8.4.4
- Cloudflare DNS: 1.1.1.1, 1.0.0.1
Connection Refused
Symptoms
- "ECONNREFUSED" errors
- "Connection refused" messages
- Can't reach Toggly servers
Solutions
1. Check Network Connectivity
# Test if you can reach Toggly
ping definitions.toggly.io
# Test HTTPS connection
curl -I https://definitions.toggly.io/.well-known/jwks
2. Check Firewall Rules
Corporate networks may block certain ports:
- Ensure port 443 (HTTPS) is open
- Check if outbound HTTPS is allowed
- Verify no firewall rules block toggly.io
3. Check Proxy Settings
# Check proxy environment variables
echo $HTTP_PROXY
echo $HTTPS_PROXY
# Unset if not needed
unset HTTP_PROXY HTTPS_PROXY
Slow Network Performance
Quick Fixes:
- Enable local caching
- Use CDN endpoints
- Minimize API calls
- Check network latency
SDK-Specific Network Configuration
- JavaScript - Fetch API configuration
- .NET - HttpClient setup
- PHP - cURL configuration
- Go - HTTP client setup
Getting Help
If network issues persist:
- Check Status Page for outages
- Test from different network to isolate the issue
- Contact support with:
- Error messages
- Network diagnostic results
- Your IP address/region
- Whether issue is consistent or intermittent