Skip to content

Commit 80be7db

Browse files
committed
Add documentation how to configure, build and run localreverseproxy. Add errors information adn requests logging in a console.
1 parent 41a4118 commit 80be7db

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*.so
99
*.dylib
1010
build
11+
localreverseproxy
1112

1213
# Test binary, built with `go test -c`
1314
*.test
@@ -20,4 +21,5 @@ build
2021

2122
# Go workspace file
2223
go.work
23-
.idea
24+
.idea
25+

README.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,65 @@
11
# Local Reverse Proxy
22
The reverse proxy server for the local environment that can help to run several docker projects locally via the 80 port.
33

4+
## How to use it
5+
1. [Download and Install Go](https://go.dev/dl/)
6+
2. Clone this repo where you want.
7+
3. Configure ports for your docker projects:
8+
- Create `docker-compose.override.yml` in a project.
9+
- Add there apache or nginx service and change a port. Because by default most of projects uses 80 or 443 ports.
10+
Yaml should look like this:
11+
```yaml
12+
services:
13+
nginx:
14+
ports: !override # helps to reset ports. Works only on the latest version of docker-compose
15+
- "8080:80" # Now set up new external port `8080`
16+
```
17+
- Recreate docker containers into your project directory.
18+
```bash
19+
docker-compose up -d --force-recreate
20+
```
21+
- Do the same steps for another docker project but use another port, as example `8090`.
22+
**Remember one port for one service/device!**
23+
> [!NOTE]
24+
> Your 2 and more projects have to run and work without any issues, if not check that external ports be unique.
25+
26+
4. Go to the directory of cloned `localreverseproxy` repository.
27+
5. Add your docker services into `services.json` file. Where:
28+
- `Key` is local domain address.
29+
- `Value` is URL:Port of docker service. Use `http://localhost:<your_service_port>`
30+
31+
> [!NOTE]
32+
> You can use simple regexp in `Key` fields of `services.json` file.
33+
> To have a mask, like: `*.local`.
34+
35+
> [!NOTE]
36+
> If you change the `services.json` file you don't need to compile app again. It is read in runtime.
37+
38+
> [!NOTE]
39+
> Don't forget add domains into your hosts file.
40+
41+
6. Let's compile Go app
42+
```bash
43+
go mod tidy
44+
go build
45+
```
46+
7. Run Local Reverse Proxy
47+
```bash
48+
./localreverseproxy
49+
```
50+
If everything ok you will see in a console
51+
```bash
52+
Reverse proxy is started.
53+
```
54+
55+
---
56+
457
## Roadmap
558
- [x] Configure routing via `json`.
659
- [x] Implement reverse-proxy functionality.
7-
- [ ] Add documentation how to use it.
60+
- [x] Add documentation how to use it.
861
- [x] Show error if port is busy.
62+
- [x] Add requests logging in console.
63+
- [ ] Add service response logging in console.
964
- [ ] Add supporting url paths.
1065
- [ ] Add supporting https.

app.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ func main() {
1616

1717
services := getMapped()
1818

19+
fmt.Println(fmt.Sprintf("Requested `%s` host with method `%s` and URI `%s`", r.Host, r.Method, r.RequestURI))
20+
1921
for servicePattern, pUrl := range services {
2022
pattern := fmt.Sprintf(`^%s$`, servicePattern)
2123
match, err := regexp.MatchString(pattern, r.Host)
2224
if err != nil {
23-
fmt.Println(err)
25+
fmt.Println(fmt.Sprintf("RegExp returned error: %s", err))
2426
continue
2527
}
2628

0 commit comments

Comments
 (0)