How evg4b/uncors works
UNCORS is a development HTTP/HTTPS proxy that maps local hosts to upstreams and replaces CORS headers. The main workflow is CLI startup, configuration-driven runtime construction, host/path routing, then a selected handler returning the response through the server. The README also documents mocking, scripting, static files, caching, rewriting, HAR capture, wildcard mapping, and generated-certificate HTTPS. Several subsystem links are documented rather than source-verified because their implementation excerpts were not provided.
Main entry points: mapping.go Config and mappings · router.go Host router · server.go HTTP server · handler.go Upstream proxy
Components 20
Startup and UI
- CLI entry
main.go - CLI commands
internal/cli/run_non_interactive.go - Interactive UI
internal/uncors_app/app.go - Terminal output
internal/tui/output.go
Configuration and runtime
- Config and mappings
internal/config/mapping.go - Runtime builder
internal/di/runtime.go
Request handling
- Host router
internal/handler/router/router.go
Proxy features
- Upstream proxy
internal/handler/proxy/handler.go - URL replacement
internal/urlreplacer/replacer.go - Request rewriting
internal/handler/rewrite/handler.go - Response mocking
internal/handler/mock - Lua scripts
internal/handler/script/handler.go - Static files
internal/handler/static/middleware.go - Response cache
internal/handler/cache/middleware.go - HAR capture
internal/handler/har/middleware.go
Server and observability
- HTTP server
internal/server/server.go - TLS certificates
internal/server/host_cert_manager.go - Request tracker
internal/server/request_tracker.go
Other components
- Developer
- Upstream service
Connections 33
- Developer → CLI entry: starts
main.go - CLI entry → CLI commands: dispatches
main.go - CLI commands → Config and mappings: loads
internal/cli/run_non_interactive.go - CLI commands → Runtime builder: builds
internal/cli/run_non_interactive.go - Runtime builder → Host router: constructs
internal/di/runtime.go - Runtime builder → Upstream proxy: configures
internal/di/runtime.go - Host router → Upstream proxy: routes default
internal/handler/router/router.go - Host router → Response mocking: routes matches
internal/handler/router/router.go - Host router → Lua scripts: routes matches
internal/handler/router/router.go - Host router → Static files: registers paths
internal/handler/router/router.go - Host router → Request rewriting: wraps routes
internal/handler/router/router.go - Host router → Response cache: wraps default
internal/handler/router/router.go - Host router → HAR capture: wraps default
internal/handler/router/router.go - Upstream proxy → URL replacement: rewrites URLs
internal/handler/proxy/handler.go - Upstream proxy → Upstream service: forwards request
internal/handler/proxy/handler.go - Upstream proxy → Upstream service: reads response
internal/handler/proxy/handler.go - CLI commands → HTTP server: starts server
internal/cli/run_non_interactive.go - Runtime builder → HTTP server: provides targets
internal/di/runtime.go - HTTP server → Host router: serves handlers
internal/server/server.go - HTTP server → Request tracker: emits events
internal/server/server.go - HTTP server → TLS certificates: uses certificates
- Developer → Interactive UI: runs interactively
- Interactive UI → HTTP server: starts and restarts
internal/uncors_app/app.go - Interactive UI → Request tracker: watches events
internal/uncors_app/app.go - Interactive UI → Terminal output: prints requests
internal/uncors_app/app.go - Config and mappings → URL replacement: defines host mappings
- Config and mappings → TLS certificates: enables HTTPS
- Config and mappings → Response mocking: configures responses
- Config and mappings → Lua scripts: configures scripts
- Config and mappings → Static files: configures serving
- Config and mappings → Response cache: configures caching
- Config and mappings → HAR capture: configures recording
- Config and mappings → Request rewriting: configures rewrites