@@ -13,13 +13,15 @@ A lightweight (1 file), dynamic reverse proxy server with live configuration rel
13
13
14
14
## Features
15
15
16
- - Live configuration reloading
17
- - Support for both local and remote proxy targets
18
- - Configurable logging options
19
- - HTTP/HTTPS support
20
- - Path-based routing
21
- - Automatic configuration file watching
22
- - Verbose logging options for debugging
16
+ - Live configuration reloading with file watching
17
+ - Support for HTTP/HTTPS proxy targets
18
+ - Static file and directory serving
19
+ - Request/Response header modification
20
+ - Configurable timeouts and retries
21
+ - Comprehensive logging options
22
+ - Graceful shutdown support
23
+ - Health check endpoint
24
+ - Environment variable configuration
23
25
24
26
## Installation
25
27
@@ -35,51 +37,139 @@ cd lightymux
35
37
go build
36
38
```
37
39
38
- ## Usage
40
+ ## Configuration
39
41
40
- Basic usage:
42
+ ### Environment Variables
41
43
42
- ``` bash
43
- ./lightymux [flags] < config_file>
44
+ - ` HTTP_ADDR ` : HTTP listen address (default: "")
45
+ - ` READ_TIMEOUT ` : Read timeout duration (default: 30s)
46
+ - ` WRITE_TIMEOUT ` : Write timeout duration (default: 30s)
47
+ - ` IDLE_TIMEOUT ` : Idle timeout duration (default: 60s)
48
+ - ` PROXY_TIMEOUT ` : Proxy timeout duration (default: 60s)
49
+ - ` VERBOSE ` : Enable verbose logging (default: false)
50
+ - ` LOG_REQUESTS ` : Log incoming requests (default: false)
51
+ - ` LOG_RESPONSES ` : Log outgoing responses (default: false)
52
+ - ` LOG_ERRORS ` : Log proxy errors (default: true)
53
+ - ` LOG_FILE ` : Log to file instead of stderr
54
+ - ` HEALTH_CHECK ` : Health check endpoint path (default: "/health")
55
+ - ` RETRY_ATTEMPTS ` : Number of retry attempts (default: 3)
56
+
57
+ ### Configuration File Format
58
+
59
+ The configuration file uses YAML format. Each route is defined by its path and target configuration:
60
+
61
+ ``` yaml
62
+ /api :
63
+ target : http://api.example.com
64
+ rules :
65
+ - request :
66
+ headers :
67
+ X-API-Key : secret-key
68
+ - response :
69
+ headers :
70
+ Access-Control-Allow-Origin : " *"
71
+
72
+ /static :
73
+ target : /var/www/static
74
+
75
+ /files :
76
+ target : /path/to/files
44
77
` ` `
45
78
46
- ### Command Line Flags
79
+ Routes can be configured for:
80
+ - Remote HTTP/HTTPS endpoints
81
+ - Local directories (static file serving)
82
+ - Single files
83
+
84
+ #### Header Modification
85
+
86
+ You can modify request and response headers for each route using three operations:
87
+
88
+ - ` header-add`: Add values to existing headers (supports multiple values)
89
+ - `header-set` : Set headers to specific values, replacing any existing ones
90
+ - `header-del` : Remove headers completely
91
+
92
+ Example :
93
+
94
+ ` ` ` yaml
95
+ /api:
96
+ target: http://api.example.com
97
+ rules:
98
+ - request:
99
+ headers:
100
+ header-add:
101
+ Accept: ["application/json", "text/plain"]
102
+ X-Custom: ["value1", "value2"]
103
+ header-set:
104
+ Authorization: "Bearer token123"
105
+ Content-Type: "application/json"
106
+ header-del:
107
+ - "X-Old-Header"
108
+ - "X-Deprecated"
109
+ - response:
110
+ headers:
111
+ header-add:
112
+ Access-Control-Allow-Methods: ["GET", "POST", "OPTIONS"]
113
+ header-set:
114
+ Access-Control-Allow-Origin: "*"
115
+ Cache-Control: "max-age=3600"
116
+ header-del:
117
+ - "X-Internal-Header"
118
+ ` ` `
47
119
48
- - ` -http ` : HTTP listen address (e.g., ":8080")
49
- - ` -verbose ` : Enable verbose logging
50
- - ` -log-requests ` : Log incoming requests
51
- - ` -log-responses ` : Log outgoing responses
52
- - ` -log-errors ` : Log proxy errors (default: true)
53
- - ` -log-file ` : Log to file instead of stderr
120
+ In this example :
121
+ - Request modifications :
122
+ - Adds multiple values to `Accept` and `X-Custom` headers
123
+ - Sets `Authorization` and `Content-Type` headers to specific values
124
+ - Removes `X-Old-Header` and `X-Deprecated` headers
125
+ - Response modifications :
126
+ - Adds multiple CORS methods
127
+ - Sets CORS origin and caching headers
128
+ - Removes an internal header
54
129
55
- ### Configuration File Format
130
+ # # Usage
56
131
57
- The configuration file uses a simple space-separated format where each line contains a path and target :
132
+ Basic usage :
58
133
134
+ ` ` ` bash
135
+ lightymux [config_file]
59
136
` ` `
60
- /path target_url_or_path
61
- /api http://api.example.com
62
- /static /var/www/static
137
+
138
+ Example with environment variables :
139
+
140
+ ` ` ` bash
141
+ HTTP_ADDR=:8080 VERBOSE=true LOG_REQUESTS=true lightymux config.yaml
63
142
` ` `
64
143
65
144
The configuration file is watched for changes and automatically reloaded when modified.
66
145
67
146
# # Example
68
147
69
- 1 . Create a configuration file ` proxy.conf ` :
70
- ```
71
- /api http://localhost:3000
72
- /static http://localhost:8080
148
+ 1. Create a configuration file `config.yaml` :
149
+ ` ` ` yaml
150
+ /api:
151
+ target: http://localhost:3000
152
+ rules:
153
+ - response:
154
+ headers:
155
+ Access-Control-Allow-Origin: "*"
156
+
157
+ /static:
158
+ target: /var/www/static
159
+
160
+ /docs:
161
+ target: http://localhost:8080
73
162
` ` `
74
163
75
164
2. Start the proxy :
76
165
` ` ` bash
77
- ./ lightymux -http :8000 proxy.conf
166
+ lightymux config.yaml
78
167
` ` `
79
168
80
- 3 . The proxy will now forward requests:
81
- - ` /api/* ` → ` http://localhost:3000/* `
82
- - ` /static/* ` → ` http://localhost:8080/* `
169
+ 3. The proxy will now :
170
+ - Forward `/api/*` to `http://localhost:3000/*` with CORS headers
171
+ - Serve static files from `/var/www/static` at `/static/*`
172
+ - Forward `/docs/*` to `http://localhost:8080/*`
83
173
84
174
# # License
85
175
0 commit comments