Skip to content

Commit

Permalink
feat: Gate Lite: Add fallback status for offline route (#217)
Browse files Browse the repository at this point in the history
Co-authored-by: jnorman-us <[email protected]>
  • Loading branch information
robinbraemer and winecraft-dev authored Jul 3, 2023
1 parent 6b33d13 commit 2632061
Show file tree
Hide file tree
Showing 15 changed files with 447 additions and 139 deletions.
30 changes: 29 additions & 1 deletion .web/docs/guide/lite.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,41 @@ config:
cachePingTTL: -1 // [!code ++]
```

## Fallback status for offline backends

If all backends of a route are unreachable, Gate Lite will return a fallback status response if configured.
You can utilize all available status fields to customize the response. (See full sample config below.)

::: code-group
```yaml [config.yml]
config:
lite:
enabled: true
routes:
- host: localhost
# The backend server to connect to if matched.
backend: localhost:25566
# The optional fallback status response when backend of this route are offline.
fallback:
motd: |
§cLocalhost server is offline.
§eCheck back later!
version:
name: '§cTry again later!'
protocol: -1
```
:::


## Sample config

The Lite configuration is located in the same Gate `config.yml` file under `lite`.

```yaml config-lite.yml
::: code-group
```yaml [config-lite.yml on GitHub]
<!--@include: ../../../config-lite.yml -->
```
:::

## Proxy behind proxy

Expand Down
17 changes: 17 additions & 0 deletions config-lite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ config:
- host: localhost
# The backend server to connect to if matched.
backend: localhost:25566
# The optional fallback status response when backend of this route are offline.
fallback:
motd: |
§cLocalhost server is offline.
§eCheck back later!
version:
name: '§cTry again later!'
protocol: -1
# The optional favicon to show in the server list (optimal 64x64).
# Accepts a path of an image file or the base64 data uri.
favicon: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH5AgJCgs6JBZy0AAAB+lJREFUeNrtmGuMXVU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ytln2LrDapiyWudUoLZK2XfbgnnAEo7bb9sKwzC6tfjyy+Um81EMAMST+XdXxeawAAzwM4EcB2AMcDuBXAgn8T8kjhgpUA+ic1CeaFMN89kNudfBGlU2V9UPZcWQ1JeyU9RvInTmk3xdmSWpSeQAC2Hpd9nqxPyjpKsmTtJLlByS+KfFqSKW4OZHAlgcBuAJdTugTAoUWcOwDsLcJ6GMAyAMsLUWYCGAWwragLGwtnYNIOAICbLz4DKe0/0R13+hI8fv+jDVlJ0miWZUOykZLHT3sUQRAUUa3X8OGrvotf3bqyRYlOaSCyLJvoIjIPpd5uoG/uO/DcMzu743i1iHOsk3U6BMffPnXPbEUdyCJigOTL3htM6jD0Sr53+VmQ07gQ432aQiBQq9cAomhdQgBo9bQg7x+eim6AyDJUm00gAikRlLCvswc9noZqT6uozvGyELvvRI5ddhUeufM7ebcgX/k+BXwNCy8pKSkpKSkpKSkpKSkpKSkpKSkpKXkz8k8RHxEbZN/8lgAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMC0wOC0wOVQxMDoxMTo0MyswMDowMN6nNEYAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjAtMDgtMDlUMTA6MTE6NDMrMDA6MDCv+oz6AAAAAElFTkSuQmCC
# You can also use * wildcard to match any subdomain.
- host: '*.example.com'
backend: 172.16.0.12:25566
Expand All @@ -40,3 +51,9 @@ config:
# Match all as last item routes any other host to a default backend.
- host: '*'
backend: 10.0.0.10:25565
fallback:
motd: §eThere is server for this host.
version:
name: §eTry example.com
protocol: -1
favicon: server-icon.png
19 changes: 18 additions & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ config:
- host: localhost
# The backend server to connect to if matched.
backend: localhost:25566
# The optional fallback status response when backend of this route are offline.
fallback:
motd: |
§cLocalhost server is offline.
§eCheck back later!
version:
name: '§cTry again later!'
protocol: -1
# The optional favicon to show in the server list (optimal 64x64).
# Accepts a path of an image file or the base64 data uri.
favicon: data:image/png;base64,iV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VIWsMwKauQQGcPSHnEcA7AawHcA+ANQAOnpQDsixDZBlk/Uj2SbZOk3WQ5B/IOhOIxyNQp3iKpJOK9naErDpJ9B15GGxvL4oWZF+i5L0A/kZruaT3jhc6KSGimwIDpMaK8fZwSStJPgLgfgB3ALgAwEIAZwEYALARQA+ACwEcUYR/RwB/4mTOAgBw43nvR6okSJoj61uyz7RV3T/Pu7uAp2ytln2LrDapiyWudUoLZK2XfbgnnAEo7bb9sKwzC6tfjyy+Um81EMAMST+XdXxeawAAzwM4EcB2AMcDuBXAgn8T8kjhgpUA+ic1CeaFMN89kNudfBGlU2V9UPZcWQ1JeyU9RvInTmk3xdmSWpSeQAC2Hpd9nqxPyjpKsmTtJLlByS+KfFqSKW4OZHAlgcBuAJdTugTAoUWcOwDsLcJ6GMAyAMsLUWYCGAWwragLGwtnYNIOAICbLz4DKe0/0R13+hI8fv+jDVlJ0miWZUOykZLHT3sUQRAUUa3X8OGrvotf3bqyRYlOaSCyLJvoIjIPpd5uoG/uO/DcMzu743i1iHOsk3U6BMffPnXPbEUdyCJigOTL3htM6jD0Sr53+VmQ07gQ432aQiBQq9cAomhdQgBo9bQg7x+eim6AyDJUm00gAikRlLCvswc9noZqT6uozvGyELvvRI5ddhUeufM7ebcgX/k+BXwNCy8pKSkpKSkpKSkpKSkpKSkpKSkpKXkz8k8RHxEbZN/8lgAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMC0wOC0wOVQxMDoxMTo0MyswMDowMN6nNEYAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjAtMDgtMDlUMTA6MTE6NDMrMDA6MDCv+oz6AAAAAElFTkSuQmCC
# You can also use * wildcard to match any subdomain.
- host: '*.example.com'
backend: 172.16.0.12:25566
Expand All @@ -141,13 +152,19 @@ config:
# You can also match to multiple hosts to one or multiple random backends.
- host: [ 127.0.0.1, localhost ]
backend: [ 172.16.0.12:25566, backend.example.com:25566 ]
# Ping responses are cached address by default.
# Ping responses are cached per backend address by default.
# To disable motd caching set it to -1.
# Default: 10s
cachePingTTL: 60s
# Match all as last item routes any other host to a default backend.
- host: '*'
backend: 10.0.0.10:25565
fallback:
motd: §eThere is server for this host.
version:
name: §eTry example.com
protocol: -1
favicon: server-icon.png

# Configuration for Connect, a network that organizes all Minecraft servers/proxies
# and makes them universally accessible for all players.
Expand Down
22 changes: 11 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ require (
github.com/sandertv/gophertunnel v1.30.0
github.com/spf13/viper v1.16.0
github.com/stretchr/testify v1.8.3
github.com/urfave/cli/v2 v2.25.6
github.com/urfave/cli/v2 v2.25.7
go.minekube.com/brigodier v0.0.1
go.minekube.com/common v0.0.5
go.minekube.com/connect v0.5.3
go.uber.org/atomic v1.11.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.24.0
golang.org/x/text v0.9.0
golang.org/x/text v0.10.0
golang.org/x/time v0.3.0
google.golang.org/grpc v1.55.0
google.golang.org/grpc v1.56.1
gopkg.in/yaml.v3 v3.0.1
nhooyr.io/websocket v1.8.7
)

require (
buf.build/gen/go/minekube/connect/protocolbuffers/go v1.30.0-20230517110945-04c17e7d2fd9.1 // indirect
buf.build/gen/go/minekube/connect/protocolbuffers/go v1.31.0-20230517110945-04c17e7d2fd9.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/df-mc/atomic v1.10.0 // indirect
Expand All @@ -49,10 +49,10 @@ require (
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/klauspost/compress v1.16.5 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
Expand All @@ -64,10 +64,10 @@ require (
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
go.uber.org/goleak v1.1.12 // indirect
golang.org/x/image v0.7.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.8.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/protobuf v1.30.0 // indirect
golang.org/x/image v0.8.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.9.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230629202037-9506855d4529 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
)
Loading

0 comments on commit 2632061

Please sign in to comment.