Skip to content
This repository was archived by the owner on Oct 5, 2025. It is now read-only.

Commit ebe254f

Browse files
committed
Remove rate limiting
1 parent a004ec1 commit ebe254f

File tree

3 files changed

+19
-91
lines changed

3 files changed

+19
-91
lines changed

README.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ GSS (Go serve SPA) is a containerized web server for single-page applications wr
77
- Optimized for single-page apps.
88
- Automatically serves pre-compressed brotli and gzip files if available.
99
- Sensible default cache configuration.
10-
- Configurable rate limiter.
1110
- Configurable response headers.
1211
- Optional out-of-the-box metrics.
1312
- Deployable as a container.
@@ -135,20 +134,6 @@ Enables metrics collection and exposes an endpoint at `:<metricsPort>/metrics`.
135134
> metrics: true
136135
> ```
137136
138-
### Rate limit per minute: `rateLimit`
139-
140-
##### string: integer
141-
142-
Configures the rate limit per minute per IP using a memory store. 15 by default.
143-
144-
> Example:
145-
>
146-
> ```yaml
147-
> # gss.yaml
148-
>
149-
> rateLimit: 10
150-
> ```
151-
152137
## Contributing
153138
154139
This project started as a way to learn and to solve a need I had. If you think it can be improved in any way, you are very welcome to contribute!

gss.go

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import (
1414
"github.com/prometheus/client_golang/prometheus/promhttp"
1515
"github.com/rs/zerolog"
1616
"github.com/rs/zerolog/log"
17-
"github.com/sethvargo/go-limiter/httplimit"
18-
"github.com/sethvargo/go-limiter/memorystore"
1917
"gopkg.in/yaml.v2"
2018
)
2119

@@ -50,11 +48,10 @@ func setUpLogger() {
5048
}
5149

5250
type config struct {
53-
FilesPort int `yaml:"filesPort,omitempty"`
54-
MetricsPort int `yaml:"metricsPort,omitempty"`
55-
ResponseHeaders map[string]string `yaml:"headers,omitempty"`
56-
MetricsEnabled bool `yaml:"metrics,omitempty"`
57-
RateLimitPerMinute int `yaml:"rateLimit,omitempty"`
51+
FilesPort int `yaml:"filesPort,omitempty"`
52+
MetricsPort int `yaml:"metricsPort,omitempty"`
53+
ResponseHeaders map[string]string `yaml:"headers,omitempty"`
54+
MetricsEnabled bool `yaml:"metrics,omitempty"`
5855
}
5956

6057
func newConfig() *config {
@@ -65,8 +62,7 @@ func newConfig() *config {
6562
ResponseHeaders: map[string]string{
6663
"Server": "GSS",
6764
},
68-
MetricsEnabled: false,
69-
RateLimitPerMinute: 15,
65+
MetricsEnabled: false,
7066
}
7167
}
7268

@@ -109,23 +105,10 @@ func newFileServer(cfg *config, metrics *metrics) *fileServer {
109105
}
110106

111107
func (f *fileServer) init() *fileServer {
112-
store, err := memorystore.New(&memorystore.Config{
113-
Tokens: uint64(f.Config.RateLimitPerMinute),
114-
Interval: time.Minute,
115-
})
116-
if err != nil {
117-
log.Fatal().Msgf("Error creating rate limit store: %v", err)
118-
}
119-
120-
rateLimit, err := httplimit.NewMiddleware(store, httplimit.IPKeyFunc())
121-
if err != nil {
122-
log.Fatal().Msgf("Error creating rate limit middleware: %v", err)
123-
}
124-
125108
if f.Config.MetricsEnabled {
126-
f.Server.Handler = metricsMiddleware(f.Metrics)(rateLimit.Handle(f.setHeaders((f.serveSPA()))))
109+
f.Server.Handler = metricsMiddleware(f.Metrics)(f.setHeaders((f.serveSPA())))
127110
} else {
128-
f.Server.Handler = rateLimit.Handle(f.setHeaders((f.serveSPA())))
111+
f.Server.Handler = f.setHeaders((f.serveSPA()))
129112
}
130113

131114
return f

gss_test.go

Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ func TestGSS(t *testing.T) {
1818
ResponseHeaders: map[string]string{
1919
"X-Test": "test",
2020
},
21-
RateLimitPerMinute: 100,
2221
}
2322
fileServer := newFileServer(cfg, metrics).init()
2423
w := httptest.NewRecorder()
@@ -29,27 +28,10 @@ func TestGSS(t *testing.T) {
2928
assert.Equal(t, "test", w.Header().Get("X-Test"))
3029
})
3130

32-
t.Run("rate limits requests", func(t *testing.T) {
33-
t.Parallel()
34-
35-
cfg := &config{
36-
RateLimitPerMinute: 100,
37-
}
38-
fileServer := newFileServer(cfg, metrics).init()
39-
w := httptest.NewRecorder()
40-
r := httptest.NewRequest(http.MethodGet, "/", nil)
41-
42-
fileServer.Server.Handler.ServeHTTP(w, r)
43-
44-
assert.NotEmpty(t, w.Header().Get("X-Ratelimit-Limit"))
45-
})
46-
4731
t.Run("redirects index correctly", func(t *testing.T) {
4832
t.Parallel()
4933

50-
cfg := &config{
51-
RateLimitPerMinute: 100,
52-
}
34+
cfg := &config{}
5335
fileServer := newFileServer(cfg, metrics).init()
5436
w := httptest.NewRecorder()
5537
r := httptest.NewRequest(http.MethodGet, "/index.html", nil)
@@ -62,9 +44,7 @@ func TestGSS(t *testing.T) {
6244
t.Run("serves HTML files succesfully", func(t *testing.T) {
6345
t.Parallel()
6446

65-
cfg := &config{
66-
RateLimitPerMinute: 100,
67-
}
47+
cfg := &config{}
6848
fileServer := newFileServer(cfg, metrics).init()
6949
w := httptest.NewRecorder()
7050
r := httptest.NewRequest(http.MethodGet, "/", nil)
@@ -79,9 +59,7 @@ func TestGSS(t *testing.T) {
7959
t.Run("serves CSS files succesfully", func(t *testing.T) {
8060
t.Parallel()
8161

82-
cfg := &config{
83-
RateLimitPerMinute: 100,
84-
}
62+
cfg := &config{}
8563
fileServer := newFileServer(cfg, metrics).init()
8664
w := httptest.NewRecorder()
8765
r := httptest.NewRequest(http.MethodGet, "/static/main.68aa49f7.css", nil)
@@ -96,9 +74,7 @@ func TestGSS(t *testing.T) {
9674
t.Run("serves JavaScript files succesfully", func(t *testing.T) {
9775
t.Parallel()
9876

99-
cfg := &config{
100-
RateLimitPerMinute: 100,
101-
}
77+
cfg := &config{}
10278
fileServer := newFileServer(cfg, metrics).init()
10379
w := httptest.NewRecorder()
10480
r := httptest.NewRequest(http.MethodGet, "/static/main.8d3db4ef.js", nil)
@@ -113,9 +89,7 @@ func TestGSS(t *testing.T) {
11389
t.Run("serves other files succesfully", func(t *testing.T) {
11490
t.Parallel()
11591

116-
cfg := &config{
117-
RateLimitPerMinute: 100,
118-
}
92+
cfg := &config{}
11993
fileServer := newFileServer(cfg, metrics).init()
12094
w := httptest.NewRecorder()
12195
r := httptest.NewRequest(http.MethodGet, "/static/main.8d3db4ef.js.LICENSE.txt", nil)
@@ -129,9 +103,7 @@ func TestGSS(t *testing.T) {
129103
t.Run("serves brotli files succesfully", func(t *testing.T) {
130104
t.Parallel()
131105

132-
cfg := &config{
133-
RateLimitPerMinute: 100,
134-
}
106+
cfg := &config{}
135107
fileServer := newFileServer(cfg, metrics).init()
136108
w := httptest.NewRecorder()
137109
r := httptest.NewRequest(http.MethodGet, "/", nil)
@@ -146,9 +118,7 @@ func TestGSS(t *testing.T) {
146118
t.Run("serves brotli files under nested folders succesfully", func(t *testing.T) {
147119
t.Parallel()
148120

149-
cfg := &config{
150-
RateLimitPerMinute: 100,
151-
}
121+
cfg := &config{}
152122
fileServer := newFileServer(cfg, metrics).init()
153123
w := httptest.NewRecorder()
154124
r := httptest.NewRequest(http.MethodGet, "/static/main.8d3db4ef.js", nil)
@@ -165,9 +135,7 @@ func TestGSS(t *testing.T) {
165135
t.Run("serves gzip files succesfully", func(t *testing.T) {
166136
t.Parallel()
167137

168-
cfg := &config{
169-
RateLimitPerMinute: 100,
170-
}
138+
cfg := &config{}
171139
fileServer := newFileServer(cfg, metrics).init()
172140
w := httptest.NewRecorder()
173141
r := httptest.NewRequest(http.MethodGet, "/", nil)
@@ -182,9 +150,7 @@ func TestGSS(t *testing.T) {
182150
t.Run("serves gzip files under nested folders succesfully", func(t *testing.T) {
183151
t.Parallel()
184152

185-
cfg := &config{
186-
RateLimitPerMinute: 100,
187-
}
153+
cfg := &config{}
188154
fileServer := newFileServer(cfg, metrics).init()
189155
w := httptest.NewRecorder()
190156
r := httptest.NewRequest(http.MethodGet, "/static/main.8d3db4ef.js", nil)
@@ -201,9 +167,7 @@ func TestGSS(t *testing.T) {
201167
t.Run("serves unexisting files without extension", func(t *testing.T) {
202168
t.Parallel()
203169

204-
cfg := &config{
205-
RateLimitPerMinute: 100,
206-
}
170+
cfg := &config{}
207171
fileServer := newFileServer(cfg, metrics).init()
208172
w := httptest.NewRecorder()
209173
r := httptest.NewRequest(http.MethodGet, "/random-page", nil)
@@ -218,9 +182,7 @@ func TestGSS(t *testing.T) {
218182
t.Run("doesn't serve unexisting files with extension", func(t *testing.T) {
219183
t.Parallel()
220184

221-
cfg := &config{
222-
RateLimitPerMinute: 100,
223-
}
185+
cfg := &config{}
224186
fileServer := newFileServer(cfg, metrics).init()
225187
w := httptest.NewRecorder()
226188
r := httptest.NewRequest(http.MethodGet, "/favicon.ico", nil)
@@ -233,9 +195,7 @@ func TestGSS(t *testing.T) {
233195
t.Run("serves a cached response for a fresh resource", func(t *testing.T) {
234196
t.Parallel()
235197

236-
cfg := &config{
237-
RateLimitPerMinute: 100,
238-
}
198+
cfg := &config{}
239199
fileServer := newFileServer(cfg, metrics).init()
240200

241201
t.Run("HTML files should have Cache-Control: no-cache", func(t *testing.T) {

0 commit comments

Comments
 (0)