-
-
Notifications
You must be signed in to change notification settings - Fork 3
Troubleshooting
This guide helps you diagnose and resolve common issues when using UNCORS.
Before diving into specific issues, verify these basics:
- UNCORS is running and showing no startup errors
- Your hosts file contains the correct domain mapping to
127.0.0.1 - The port in your UNCORS configuration matches the port you're accessing
- Your browser/client is not using a proxy that bypasses localhost
- CORS errors are actually UNCORS-related (check browser console)
Symptoms:
- Browser shows "Connection refused" or "Cannot connect"
-
curlreturns "Failed to connect to [domain]"
1. UNCORS is not running
# Check for UNCORS process
ps aux | grep uncors
# Start UNCORS if not running
uncors --config .uncors.yaml2. Wrong port in URL
Verify the port matches your configuration:
mappings:
- from: http://api.local:3000 # Port 3000
to: https://api.example.comcurl http://api.local:3000/ # Correct
curl http://api.local:8080/ # Wrong - will fail3. Hosts file not configured
Verify hosts file entry:
# macOS/Linux
cat /etc/hosts | grep api.local
# Windows (PowerShell)
Get-Content C:\Windows\System32\drivers\etc\hosts | Select-String api.localExpected output: 127.0.0.1 api.local. If missing, see Installation → Hosts
File Setup.
4. DNS cache not flushed
After modifying the hosts file, flush the DNS cache:
# macOS
sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder
# Linux (systemd)
sudo systemctl restart systemd-resolved# Windows
ipconfig /flushdnsSymptoms:
- "NET::ERR_CERT_INVALID" in browser
- "SSL certificate problem" in curl
- "Unable to verify the first certificate"
1. CA certificate not generated
uncors generate-certsThis creates ~/.config/uncors/ca.crt and ~/.config/uncors/ca.key.
2. CA certificate not trusted
macOS:
open ~/.config/uncors/ca.crt
# Set to "Always Trust" in Keychain AccessLinux:
sudo cp ~/.config/uncors/ca.crt /usr/local/share/ca-certificates/uncors-ca.crt
sudo update-ca-certificatesWindows:
certutil -addstore -user "Root" %USERPROFILE%\.config\uncors\ca.crt3. Browser not using system certificates
Firefox maintains its own certificate store:
- Settings → Privacy & Security → Certificates → View Certificates
- Import
~/.config/uncors/ca.crtunder the "Authorities" tab
4. CA certificate expired
# Check expiry
openssl x509 -in ~/.config/uncors/ca.crt -noout -dates
# Regenerate if expired
uncors generate-certs --forceThen re-trust the new certificate.
5. Development bypass (not recommended for regular use)
# curl: ignore certificate errors
curl -k https://api.local:8443/Symptoms:
- Browser console shows CORS errors despite using UNCORS
- "Access-Control-Allow-Origin" header errors
1. Request not going through UNCORS
Enable debug logging and verify requests appear in the output:
uncors --config .uncors.yaml --debug2. OPTIONS request being forwarded instead of handled
By default, UNCORS handles OPTIONS requests locally. If disabled, the upstream server must handle them:
mappings:
- from: http://api.local:3000
to: https://api.example.com
options-handling:
disabled: false # Must be false (default) for UNCORS to handle preflight3. Custom headers overriding CORS headers
If you've set custom CORS headers in mocks or scripts, verify they're correct:
mocks:
- path: /api/test
response:
code: 200
headers:
Access-Control-Allow-Origin: "*"
Access-Control-Allow-Methods: "GET, POST, OPTIONS"
raw: "test"4. Browser cache contains old CORS responses
Clear browser cache (Chrome: Ctrl+Shift+Delete, macOS: Cmd+Shift+Delete) or
use an incognito/private window.
Symptoms:
- UNCORS starts but doesn't apply configuration
- "No mappings configured" error
- Configuration changes not taking effect
1. Wrong configuration file path
ls -l .uncors.yaml # Should exist
uncors --config .uncors.yaml --debugUse an absolute path if a relative path fails:
uncors --config /absolute/path/to/.uncors.yaml2. YAML syntax errors
Validate YAML syntax:
python3 -c "import yaml; yaml.safe_load(open('.uncors.yaml'))"Common YAML mistakes:
- Incorrect indentation (use spaces, not tabs)
- Missing colons after keys
- Unquoted special characters
3. Configuration not reloaded after changes
UNCORS does not auto-reload configuration. Restart after changes:
# Stop UNCORS with Ctrl+C, then restart
uncors --config .uncors.yamlSymptoms:
- Mock responses not returned
- Requests still going to the upstream server
1. Path doesn't match exactly
mocks:
- path: /api/users # Matches /api/users but NOT /api/users/
response:
code: 200
raw: "mock response"Use path variables for flexibility:
mocks:
- path: /api/users/{id}
response:
code: 200
raw: '{"id": "123"}'2. HTTP method filter too restrictive
If you specify a method, only that method is matched:
mocks:
- path: /api/users
method: POST # Only matches POST requests; GET requests pass through3. Mock file not found
mocks:
- path: /api/data
response:
code: 200
file: ./mock-data.json # Verify this file existsls -l ./mock-data.jsonSymptoms:
- 404 errors when accessing static files
- Files not loaded from local directory
1. Directory path incorrect
ls -la ~/project/distUse an absolute path in the configuration if needed:
statics:
- path: /assets
dir: /absolute/path/to/assets2. Path prefix doesn't match
With the configuration below, the URL must include the /assets prefix:
statics:
- path: /assets
dir: ~/project/distcurl http://api.local:3000/assets/style.css # Correct
curl http://api.local:3000/style.css # Wrong - prefix missing3. Missing index file for SPA routing
statics:
- path: /
dir: ~/project/build
index: index.html # Required for client-side routingSymptoms:
- UNCORS process consuming excessive resources
- System slowdown when UNCORS is running
1. Cache growing too large
Configure a shorter expiration time or smaller max size:
cache-config:
expiration-time: 5m
max-size: 52428800 # 50 MBOr disable caching for this mapping by omitting the cache: section entirely.
2. Debug logging enabled
debug: false3. Large response bodies being cached
Only cache paths that return small responses:
cache:
- /api/small-responses/**
# Avoid caching /api/large-files/**Symptoms:
- Requests fail with proxy errors
- "Proxy connection failed"
1. Proxy URL format incorrect
proxy: http://proxy.example.com:8080 # Correct formatTest connectivity:
curl -x http://proxy.example.com:8080 https://google.com2. Environment variables conflicting
UNCORS reads system proxy environment variables by default. Unset them if needed:
unset HTTP_PROXY HTTPS_PROXY http_proxy https_proxyOr override in the configuration:
proxy: "" # Disable proxy3. Proxy requires authentication
proxy: http://username:password@proxy.example.com:8080Script Not Executing
Symptoms: Script handler not running; default response returned instead.
1. Path or method filter doesn't match
scripts:
- path: /api/custom
method: GET
script: |
response:WriteHeader(200)
response:WriteString("Hello")Verify the path and method match your request exactly.
2. Script syntax error
Enable debug logging to see script errors:
uncors --config .uncors.yaml --debug3. File-based script not found
scripts:
- path: /api/custom
file: ~/scripts/handler.lua # Verify file existsls -l ~/scripts/handler.luaSlow response times:
- Enable caching for frequently accessed resources
cache-config:
expiration-time: 10m
methods: [GET]
mappings:
- from: http://api.local:3000
to: https://api.example.com
cache:
- /api/**- Check upstream server response time directly
time curl https://api.example.com/endpoint- Ensure the upstream server supports compression (gzip, br)
uncors --config .uncors.yaml --debuguncors --versionIf you've tried the above and still have problems, create an issue at GitHub Issues with:
- UNCORS version (
uncors --version) - Operating system
- Configuration file (with sensitive values removed)
- Debug logs
- Steps to reproduce
- Always use debug mode during initial setup to see what requests are being handled
- Validate your YAML before starting - syntax errors produce confusing startup behavior
- Keep UNCORS updated:
brew upgrade evg4b/tap/uncors # Homebrew
npm update -g uncors # NPM- Document your setup - note hosts file entries, certificate locations, and config paths
-
Version control your configuration - commit
.uncors.yamlalongside your project