-
-
Notifications
You must be signed in to change notification settings - Fork 3
Migration Guide
This guide helps you migrate your UNCORS configuration files when upgrading between versions. Breaking changes are documented with before/after examples.
This is a major version with several breaking changes. Review all three sections before upgrading.
Breaking Change: Global cert-file and key-file configuration properties
have been removed from the root level. TLS certificates must now use
auto-generated certificates with a local CA.
The previous architecture required all HTTPS mappings to share the same certificate. The new approach uses auto-generated certificates with a local CA, providing greater flexibility, SNI support, and simpler configuration.
Old Configuration (v0.5.x and earlier):
cert-file: ~/certs/server.crt
key-file: ~/certs/server.key
mappings:
- from: https://app.local:8443
to: https://api.example.com
- from: https://admin.local:8443
to: https://admin.example.comNew Configuration (v0.6.x):
mappings:
- from: https://app.local:8443
to: https://api.example.com
- from: https://admin.local:8443
to: https://admin.example.comBefore using HTTPS mappings, generate a local CA once:
uncors generate-certsThis creates ~/.config/uncors/ca.crt. Add this certificate to your system's
trusted certificates to avoid browser warnings.
Key Changes:
-
Remove the global
cert-fileandkey-fileproperties -
Run
uncors generate-certsto create a local CA - Trust the CA certificate in your system's certificate store
- Automatic certificate generation for any host
- No need to manage certificate files
- SNI (Server Name Indication) support - multiple hosts on the same port
- Certificates cached in memory, regenerated only when needed
Breaking Change: Global http-port and https-port configuration
properties have been removed. Ports are now specified directly in the mapping
URLs.
The previous architecture required all HTTP mappings to share the same port and all HTTPS mappings to share the same port. The new per-mapping port configuration allows each mapping to listen on its own port.
Old Configuration (v0.5.x and earlier):
http-port: 8080
https-port: 8443
mappings:
- from: http://localhost
to: https://api.example.com
- from: https://secure-app
to: https://backend.example.comNew Configuration (v0.6.x):
mappings:
- from: http://localhost:8080
to: https://api.example.com
- from: https://secure-app:8443
to: https://backend.example.comKey Changes:
-
Remove the global
http-portandhttps-portproperties -
Add the port number directly to the
fromURL:protocol://host:port - Ports default to 80 for HTTP and 443 for HTTPS when omitted
The new architecture enables each mapping to use a different port:
mappings:
- from: http://api.local:3000
to: https://api.example.com
- from: http://admin.local:4000
to: https://admin.example.com
- from: https://secure.local:8443
to: https://backend.example.comOld:
http-port: 8080
mappings:
- http://localhost: https://github.comNew:
mappings:
- http://localhost:8080: https://github.comOld:
uncors --http-port 8080 --from http://localhost --to https://api.example.comNew:
uncors --from http://localhost:8080 --to https://api.example.comOld:
http-port: 8080
mappings:
- from: http://*.local.com
to: https://*.example.comNew:
mappings:
- from: http://*.local.com:8080
to: https://*.example.comBreaking Change: The fake field for generating mock responses with fake
data has been removed. Use Lua script handlers instead for dynamic response
generation.
The Lua script handler provides a more flexible and powerful way to generate dynamic responses. It allows for complex logic, external command execution, and better maintainability.
Old Configuration (v0.5.x and earlier):
mappings:
- from: http://localhost:8080
to: https://api.example.com
mocks:
- path: /api/users
response:
code: 200
fake:
type: object
properties:
login:
type: email
username:
type: username
seed: 12345New Configuration (v0.6.x) - Using Script Handler:
mappings:
- from: http://localhost:8080
to: https://api.example.com
scripts:
- path: /api/users
script: |
local handle = io.popen("fakedata --format=ndjson --limit 1 login=email username=username")
local output = handle:read("*a")
handle:close()
response.headers["Content-Type"] = "application/json"
response:WriteHeader(200)
response:WriteString(output)Key Changes:
-
Remove the
mockssection withfakeandseedproperties -
Add a
scriptssection with a Lua script handler - Use the fakedata CLI tool or any other tool of your choice
macOS:
brew install lucapette/tap/fakedataLinux/macOS with Go:
go install github.com/lucapette/fakedata@latestOld:
response:
code: 200
fake:
type: array
item:
type: object
properties:
name:
type: name
email:
type: email
count: 5New:
scripts:
- path: /api/users
script: |
local handle = io.popen("fakedata --format=ndjson --limit 5 name=name email=email")
local output = handle:read("*a")
handle:close()
-- Convert NDJSON to JSON array
local lines = {}
for line in output:gmatch("[^\n]+") do
table.insert(lines, line)
end
local result = "[" .. table.concat(lines, ",") .. "]"
response.headers["Content-Type"] = "application/json"
response:WriteHeader(200)
response:WriteString(result)- More flexible: Execute any command-line tool, not just fake data generation
- Better control: Use Lua logic for complex data transformations
-
External tools: Leverage
fakedata,faker-cli, or custom scripts - Full language: Access to Lua's complete capabilities for complex scenarios
For more information, see the Script Handler documentation.
If you encounter issues during migration:
- Check the Configuration documentation for the current format
- Review the JSON Schema for configuration validation
- Enable debug mode:
uncors --config .uncors.yaml --debug - Report issues at GitHub Issues