Skip to content

Commit da2a7fe

Browse files
authored
Develop (#7)
* here we go......... * updated swagger docs * chore(push): 0.3.0 * feat(hmm): update changelog date * feat(add): github stuff * feat(add): cors fix * Remove AllowCredentials from CORS settings Removed AllowCredentials setting from CORS configuration. * chore: run code formatter * fix: cors origins parsing issue
1 parent 89990f4 commit da2a7fe

7 files changed

Lines changed: 27 additions & 22 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,7 @@ logs/
4949
tmp/
5050
temp/
5151
*.tmp
52+
53+
db
54+
migrate
55+

.golangci.yml

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
run:
22
timeout: 5m
33
tests: true
4-
skip-dirs:
5-
- vendor
6-
- bin
74
go: '1.24'
85

96
linters:
107
enable:
11-
- aconv
128
- asciicheck
139
- bidichk
1410
- bodyclose
@@ -26,7 +22,6 @@ linters:
2622
- forbidigo
2723
- forcetypeassert
2824
- funlen
29-
- gocheckcompileerrors
3025
- gochecksumtype
3126
- gocritic
3227
- gocyclo
@@ -59,7 +54,6 @@ linters:
5954
- mnd
6055
- musttag
6156
- nakedret
62-
- nargout
6357
- nestif
6458
- nilerr
6559
- nilnil
@@ -78,14 +72,9 @@ linters:
7872
- reassign
7973
- revive
8074
- rowserrcheck
81-
- rowsclose
8275
- sloglint
83-
- slurp
8476
- spancheck
85-
- sqlc
8677
- staticcheck
87-
- stdlibuserspace
88-
- strconcat
8978
- tagalign
9079
- tagliatelle
9180
- tenv
@@ -95,10 +84,7 @@ linters:
9584
- tparallel
9685
- typecheck
9786
- unconvert
98-
- undeclaredname
9987
- unparam
100-
- unsafeptr
101-
- unusedvars
10288
- usestdlibvars
10389
- wastedassign
10490
- whitespace
@@ -124,7 +110,7 @@ linters-settings:
124110
min-complexity: 10
125111

126112
govet:
127-
check-shadowing: true
113+
disable-all: false
128114

129115
lll:
130116
line-length: 120
@@ -148,14 +134,14 @@ linters-settings:
148134
- name: unused-parameter
149135
- name: unused-receiver
150136

151-
staticcheck:
152-
go: '1.24'
153-
154137
unparam:
155138
check-exported: false
156139

157140
issues:
158141
exclude-use-default: false
142+
exclude-dirs:
143+
- vendor
144+
- bin
159145
exclude:
160146
# G101 is about environment variable handling
161147
- G101

cmd/api/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"context"
2323
"os"
2424
"os/signal"
25+
"strings"
2526
"syscall"
2627
"time"
2728

@@ -221,9 +222,10 @@ func setupMiddleware(app *fiber.App, sentryHandler fiber.Handler, cfg *config.Co
221222
Format: "[${time}] ${status} - ${latency} ${method} ${path}\n",
222223
}))
223224
app.Use(cors.New(cors.Config{
224-
AllowOrigins: cfg.CORSOrigins,
225+
AllowOrigins: strings.Join(cfg.CORSOrigins, ","),
225226
AllowHeaders: "Origin, Content-Type, Accept, Authorization, X-API-Key",
226227
AllowMethods: "GET, POST, PUT, DELETE, OPTIONS, PATCH",
228+
AllowCredentials: true,
227229
}))
228230
}
229231

db

-12.7 MB
Binary file not shown.

internal/config/config.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"os"
88
"strconv"
9+
"strings"
910

1011
"github.com/nodebyte/backend/internal/crypto"
1112
"github.com/nodebyte/backend/internal/database"
@@ -27,7 +28,7 @@ type Config struct {
2728
APIKey string
2829

2930
// CORS
30-
CORSOrigins string
31+
CORSOrigins []string
3132

3233
// Pterodactyl Panel
3334
PterodactylURL string
@@ -68,7 +69,7 @@ func Load() (*Config, error) {
6869
DatabaseURL: os.Getenv("DATABASE_URL"),
6970
RedisURL: getEnv("REDIS_URL", "localhost:6379"),
7071
APIKey: os.Getenv("BACKEND_API_KEY"),
71-
CORSOrigins: getEnv("CORS_ORIGINS", "*"),
72+
CORSOrigins: parseCORSOrigins(getEnv("CORS_ORIGINS", "https://nodebyte.host")),
7273

7374
// Panel settings
7475
PterodactylURL: os.Getenv("PTERODACTYL_URL"),
@@ -131,6 +132,16 @@ func getEnvBool(key string, defaultValue bool) bool {
131132
return defaultValue
132133
}
133134

135+
func parseCORSOrigins(originsStr string) []string {
136+
var origins []string
137+
for _, origin := range strings.Split(originsStr, ",") {
138+
if trimmed := strings.TrimSpace(origin); trimmed != "" {
139+
origins = append(origins, trimmed)
140+
}
141+
}
142+
return origins
143+
}
144+
134145
// MergeFromDB loads configuration overrides from the `config` table in the
135146
// main application database. Values stored in the DB will overwrite the
136147
// corresponding fields on the provided Config when present.

internal/config/config_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ func TestLoad(t *testing.T) {
9999
},
100100
expectErr: false,
101101
checkFn: func(cfg *Config) bool {
102-
return cfg.CORSOrigins == "https://example.com,https://app.example.com"
102+
return len(cfg.CORSOrigins) == 2 &&
103+
cfg.CORSOrigins[0] == "https://example.com" &&
104+
cfg.CORSOrigins[1] == "https://app.example.com"
103105
},
104106
},
105107
{

migrate

-12.7 MB
Binary file not shown.

0 commit comments

Comments
 (0)