https://github.com/lacocoroco/code-server-reverse-proxy
https://github.com/lacocoroco/code-server-reverse-proxy
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/lacocoroco/code-server-reverse-proxy
- Owner: LaCocoRoco
- License: mit
- Created: 2025-06-11T07:18:42.000Z (12 months ago)
- Default Branch: master
- Last Pushed: 2025-06-11T08:00:18.000Z (12 months ago)
- Last Synced: 2025-06-11T08:49:57.296Z (12 months ago)
- Language: Go
- Size: 3.91 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
Awesome Lists containing this project
README
## README
This project addresses routing issues encountered when using applications proxied through Code Server. Code Server's proxy functionality often requires application-specific routing adjustments which aren't always feasible. This solution provides a mechanism to rewrite the `proxy/` path to a subdomain, enabling access via a more conventional URL structure.
### Functionality
The Go script acts as a reverse proxy and URL rewriting service. It intercepts requests and performs the following:
1. **Rewrite:** If a request is made to `proxy/`, the script rewrites the URL to `.domain.com` and redirects the client. For example, a request to `proxy.domain.com/proxy/9000` will redirect to `9000.domain.com`.
2. **Subdomain Reverse Proxy:** If a request is made directly to a subdomain (e.g., `9000.domain.com`), the script forwards the request to a configurable target base URL with the port appended.
### Configuration
The script's behavior is controlled by the following environment variables:
- `DOMAIN_SUFFIX`: The domain suffix used for subdomain creation (e.g., `example.com`).
- `TARGET_BASE_URL`: The base URL of the target application (e.g., `http://localhost`).
- `SERVER_PORT`: The port on which the Go script listens for incoming requests.
### Example Usage
Assuming the following configuration:
- `DOMAIN_SUFFIX=example.com`
- `TARGET_BASE_URL=http://localhost`
- `SERVER_PORT=8081`
A request to `proxy.example.com/proxy/9000` will redirect to `9000.example.com`. Requests to `9000.example.com` will be proxied to `http://localhost:9000`.
### Integration with Code Server & Wildcard Subdomain Handling
This script is designed to be used in conjunction with Code Server. Configure Code Server to proxy requests to this script.To enable access via wildcard subdomains (e.g., `*.example.com`), configure your DNS to resolve all subdomain requests to the server running this script. The script then handles the URL rewriting and reverse proxying to the underlying applications. The following example demonstrates how a request to `proxy/` is redirected to the wildcard subdomain: A request to `proxy.example.com/proxy/9000` is initially received by the server. The script then redirects the client to `9000.example.com`, effectively utilizing the wildcard DNS configuration.
### Security Considerations
This project focuses on routing and URL rewriting. Security measures, such as authentication and authorization, are the responsibility of the user and should be implemented separately.
### Caddy Configuration Example (Reference)
The following Caddyfile snippet demonstrates how to integrate this script with Caddy as a reverse proxy:
```caddyfile
*.example.com {
reverse_proxy http://x.x.x.x:8081
}
coder.example.com {
@proxyPath path_regexp proxyPath ^/proxy/(\d+)
redir @proxyPath https://proxy.example.com{uri}
reverse_proxy http://x.x.x.x:8080
}
```