Commit 13d32db
authored
feat: add base path support for reverse proxy deployments (#157)
Add -base-path configuration option to enable WStunnel server deployment
behind reverse proxies (Envoy, Istio, nginx) with path-based routing.
## Summary
* Add -base-path command-line flag to configure base path prefix
* Implement automatic path normalization (leading/trailing slashes)
* Update HTTP route registration to use base path prefixes
* Add URL rewriting middleware to strip base path from requests
* Preserve existing functionality when no base path is configured
## Features
* **Base Path Configuration**: New -base-path flag for server deployment
* **Path Normalization**: Automatic handling of leading/trailing slashes
* **Route Prefixing**: All endpoints (/_tunnel, /_health_check, /_stats, /_token/)
support base paths
* **URL Rewriting**: Transparent base path removal before request processing
* **Backward Compatibility**: No impact on existing deployments
## Implementation Details
* Added BasePath field to WSTunnelServer struct
* Created normalizeBasePath() helper for path validation
* Implemented shouldStripBasePath() for proper URL matching
* Added buildPath() utility for route construction
* Enhanced HTTP handler wrapper for automatic path stripping
## Testing
* Comprehensive unit tests for path normalization and URL rewriting
* Integration tests with real HTTP servers and various base path
configurations
* Edge case testing for empty paths, root paths, and special characters
* All existing tests continue to pass
## Documentation
* Updated README.md with base path configuration examples
* Enhanced CLAUDE.md with operational guidance
* Created comprehensive proxy configuration examples (Envoy, Istio, nginx,
HAProxy)
* Added Kubernetes deployment examples and troubleshooting guide
## Use Cases
This enables WStunnel deployment in modern containerized environments:
* Kubernetes ingress controllers with path-based routing
* Istio service mesh with VirtualService path matching
* Envoy proxy configurations with prefix routing
* nginx reverse proxy setups with location blocks
* API gateway deployments with versioned paths
## Example Usage
```bash
# Deploy behind reverse proxy at /wstunnel path
./wstunnel srv -port 8080 -base-path /wstunnel
# Access endpoints with base path
curl http://proxy.example.com/wstunnel/_health_check
curl http://proxy.example.com/wstunnel/_stats
```
Fixes #1291 parent 19d805d commit 13d32db
File tree
5 files changed
+1356
-9
lines changed- docs
- tunnel
5 files changed
+1356
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| 81 | + | |
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
| 85 | + | |
84 | 86 | | |
85 | 87 | | |
86 | 88 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
106 | 117 | | |
107 | 118 | | |
108 | 119 | | |
| |||
136 | 147 | | |
137 | 148 | | |
138 | 149 | | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
139 | 165 | | |
140 | 166 | | |
141 | 167 | | |
142 | 168 | | |
| 169 | + | |
143 | 170 | | |
144 | 171 | | |
145 | 172 | | |
| |||
161 | 188 | | |
162 | 189 | | |
163 | 190 | | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
164 | 198 | | |
165 | 199 | | |
166 | 200 | | |
167 | 201 | | |
| 202 | + | |
| 203 | + | |
168 | 204 | | |
169 | 205 | | |
170 | 206 | | |
| |||
186 | 222 | | |
187 | 223 | | |
188 | 224 | | |
189 | | - | |
190 | 225 | | |
191 | 226 | | |
192 | 227 | | |
193 | 228 | | |
194 | 229 | | |
195 | 230 | | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
196 | 240 | | |
197 | 241 | | |
198 | 242 | | |
| |||
270 | 314 | | |
271 | 315 | | |
272 | 316 | | |
273 | | - | |
| 317 | + | |
274 | 318 | | |
275 | 319 | | |
276 | 320 | | |
| |||
0 commit comments