Skip to content

Commit e48635c

Browse files
authored
Merge pull request #7 from Plaenkler/development
Added support for proxy operation
2 parents dbeb535 + 3c3c931 commit e48635c

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ DDNS provides a straightforward way to update dynamic DNS entries without fiddli
3535

3636
### Deploy with Docker
3737

38-
It is recommended to use [docker-compose](https://docs.docker.com/compose/) as it is very convenient. The following example shows a simple deployment without a proxy.
38+
It is recommended to use [docker-compose](https://docs.docker.com/compose/) as it is very convenient. The following example shows a simple deployment:
3939

4040
```yaml
4141
---
@@ -59,6 +59,8 @@ networks:
5959
external: false
6060
```
6161
62+
> **Note:** DDNS can also be operated behind a proxy like [Traefik](https://doc.traefik.io/traefik/).
63+
6264
### Build from source
6365
6466
From the root of the source tree, run:
@@ -67,7 +69,7 @@ From the root of the source tree, run:
6769
go build -o ddns.exe cmd/main.go
6870
```
6971

70-
> Make sure that CGO is operational!
72+
> **Note:** Make sure that CGO is operational!
7173
7274
### Configuration
7375

pkg/router/router.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,17 @@ func (manager *Manager) Start() {
5252
ReadHeaderTimeout: 3 * time.Second,
5353
WriteTimeout: 3 * time.Second,
5454
IdleTimeout: 120 * time.Second,
55-
Handler: manager.Router,
55+
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
56+
// Read X-Forwarded-For-Header for proxying
57+
remoteIP := r.Header.Get("X-Forwarded-For")
58+
remotePort := r.Header.Get("X-Forwarded-Port")
59+
if remotePort == "" {
60+
remotePort = "80"
61+
}
62+
r.URL.Scheme = "http"
63+
r.URL.Host = fmt.Sprintf("%s:%s", remoteIP, remotePort)
64+
manager.Router.ServeHTTP(w, r)
65+
}),
5666
}
5767
err = server.ListenAndServe()
5868
if err != nil {

0 commit comments

Comments
 (0)