https://github.com/akullpp/groxy
Simple reverse proxy to proxy requests based on the first path segment to the correct service in order to substitute services partially in local development
https://github.com/akullpp/groxy
Last synced: about 1 year ago
JSON representation
Simple reverse proxy to proxy requests based on the first path segment to the correct service in order to substitute services partially in local development
- Host: GitHub
- URL: https://github.com/akullpp/groxy
- Owner: akullpp
- License: mit
- Created: 2020-11-09T12:08:19.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-12-13T22:17:38.000Z (over 4 years ago)
- Last Synced: 2025-04-14T11:05:20.435Z (about 1 year ago)
- Language: Go
- Size: 5.86 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Reverse Proxy
Simple reverse proxy to proxy requests based on the first path segment to the correct service in order to substitute services partially in local development.
## Installation
```
git clone https://github.com/akullpp/groxy.git
```
## Configuration
Create a `.env.local` of the following form:
```
FOO=http://localhost:1000
BAR=http://localhost:2000
```
* Requests which paths start with `FOO` (e.g. `foo/baz`) will be forwarded to `http://localhost:1000` (e.g `http://localhost:1000/foo/baz`).
* Requests which paths start with `BAR` (e.g. `bar/baz`) will be forwarded to `http://localhost:2000` (e.g `http://localhost:2000/bar/baz`).
* Requests which first path segment do not match will be forwarded to the DEFAULT value in `.env` (e.g. `http://localhost:8080`).
You also have the ability to drop the path prefix, by adding `_DROP_PREFIX=true`, e.g.
```
FOO=http://localhost:1000
BAR=http://localhost:2000
BAR_DROP_PREFIX=true
```
This will forward requests of `localhost:9999/bar/baz` to `localhost:2000/baz`.
### Usage
```
go run ./main.go
```
I suggest to use [reflex](https://github.com/cespare/reflex) in order to restart the server if the `.env.local` changes:
```
reflex -r '\.env\.local' -s -- sh -c 'go run ./main.go'
```
## Example
If you want to route requests that start with `user` to `http://localhost:8100`:
```
USER=http://localhost:8100
```
## Dependencies
I extracted the reading of the reading of environment files to another package (see [gotenv](https://github.com/akullpp/gotenv)) which only uses the standard library.