Skip to content

Commit bb3f43d

Browse files
authored
feat: Set sane defaults for all URIs (#22)
1 parent 25a0d49 commit bb3f43d

File tree

3 files changed

+38
-29
lines changed

3 files changed

+38
-29
lines changed

README.md

-3
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@ pnpm start
116116

117117
```sh
118118
export N8N_LAUNCHER_LOG_LEVEL=debug
119-
export N8N_MAIN_URI=... # e.g. http://127.0.0.1:5678
120-
export N8N_TASK_BROKER_URI=... # e.g. http://127.0.0.1:5679
121-
export N8N_RUNNER_URI=... # e.g. http://127.0.0.1:5680
122119
export N8N_RUNNERS_AUTH_TOKEN=... # i.e. same string as in step 4
123120

124121
make run

internal/env/env.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ const (
5454
)
5555

5656
const (
57-
defaultIdleTimeoutValue = "15" // seconds
57+
defaultIdleTimeoutValue = "15" // seconds
58+
DefaultMainServerURI = "http://127.0.0.1:5678"
59+
DefaultTaskBrokerServerURI = "http://127.0.0.1:5679"
60+
DefaultRunnerServerURI = "http://127.0.0.1:5680"
5861
)
5962

6063
// AllowedOnly filters the current environment down to only those
@@ -143,19 +146,19 @@ func FromEnv() (*EnvConfig, error) {
143146
}
144147

145148
if mainServerURI == "" {
146-
errs = append(errs, fmt.Errorf("%s is required", EnvVarMainServerURI))
149+
mainServerURI = DefaultMainServerURI
147150
} else if err := validateURL(mainServerURI, EnvVarMainServerURI); err != nil {
148151
errs = append(errs, err)
149152
}
150153

151154
if runnerServerURI == "" {
152-
errs = append(errs, fmt.Errorf("%s is required", EnvVarRunnerServerURI))
155+
runnerServerURI = DefaultRunnerServerURI
153156
} else if err := validateURL(runnerServerURI, EnvVarRunnerServerURI); err != nil {
154157
errs = append(errs, err)
155158
}
156159

157160
if taskBrokerServerURI == "" {
158-
errs = append(errs, fmt.Errorf("%s is required", EnvVarTaskBrokerServerURI))
161+
taskBrokerServerURI = DefaultTaskBrokerServerURI
159162
} else if err := validateURL(taskBrokerServerURI, EnvVarTaskBrokerServerURI); err != nil {
160163
errs = append(errs, err)
161164
}

internal/env/env_test.go

+31-22
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,23 @@ func TestFromEnv(t *testing.T) {
148148
name string
149149
envVars map[string]string
150150
expectError bool
151+
expected *EnvConfig
151152
}{
152153
{
153-
name: "valid configuration",
154+
name: "valid custom configuration",
154155
envVars: map[string]string{
155156
EnvVarAuthToken: "token123",
156-
EnvVarMainServerURI: "http://localhost:5678",
157-
EnvVarTaskBrokerServerURI: "http://localhost:5679",
158-
EnvVarRunnerServerURI: "http://localhost:5680",
157+
EnvVarMainServerURI: "http://localhost:9000",
158+
EnvVarTaskBrokerServerURI: "http://localhost:9001",
159+
EnvVarRunnerServerURI: "http://localhost:9002",
159160
EnvVarIdleTimeout: "30",
160161
},
161-
expectError: false,
162+
expected: &EnvConfig{
163+
AuthToken: "token123",
164+
MainServerURI: "http://localhost:9000",
165+
TaskBrokerServerURI: "http://localhost:9001",
166+
RunnerServerURI: "http://localhost:9002",
167+
},
162168
},
163169
{
164170
name: "missing auth token",
@@ -186,7 +192,12 @@ func TestFromEnv(t *testing.T) {
186192
EnvVarTaskBrokerServerURI: "http://localhost:5679",
187193
EnvVarRunnerServerURI: "http://localhost:5680",
188194
},
189-
expectError: true,
195+
expected: &EnvConfig{
196+
AuthToken: "token123",
197+
MainServerURI: DefaultMainServerURI,
198+
TaskBrokerServerURI: "http://localhost:5679",
199+
RunnerServerURI: "http://localhost:5680",
200+
},
190201
},
191202
{
192203
name: "invalid task broker server URI",
@@ -205,7 +216,12 @@ func TestFromEnv(t *testing.T) {
205216
EnvVarMainServerURI: "http://localhost:5678",
206217
EnvVarRunnerServerURI: "http://localhost:5680",
207218
},
208-
expectError: true,
219+
expected: &EnvConfig{
220+
AuthToken: "token123",
221+
MainServerURI: "http://localhost:5678",
222+
TaskBrokerServerURI: DefaultTaskBrokerServerURI,
223+
RunnerServerURI: "http://localhost:5680",
224+
},
209225
},
210226
{
211227
name: "invalid runner server URI",
@@ -224,7 +240,12 @@ func TestFromEnv(t *testing.T) {
224240
EnvVarMainServerURI: "http://localhost:5678",
225241
EnvVarTaskBrokerServerURI: "http://localhost:5679",
226242
},
227-
expectError: true,
243+
expected: &EnvConfig{
244+
AuthToken: "token123",
245+
MainServerURI: "http://localhost:5678",
246+
TaskBrokerServerURI: "http://localhost:5679",
247+
RunnerServerURI: DefaultRunnerServerURI,
248+
},
228249
},
229250
{
230251
name: "missing scheme in 127.0.0.1 URI",
@@ -296,20 +317,8 @@ func TestFromEnv(t *testing.T) {
296317
return
297318
}
298319

299-
if envCfg.AuthToken != tt.envVars[EnvVarAuthToken] {
300-
t.Errorf("FromEnv() AuthToken = %v, want %v", envCfg.AuthToken, tt.envVars[EnvVarAuthToken])
301-
}
302-
303-
if envCfg.MainServerURI != tt.envVars[EnvVarMainServerURI] {
304-
t.Errorf("FromEnv() MainServerURI = %v, want %v", envCfg.MainServerURI, tt.envVars[EnvVarMainServerURI])
305-
}
306-
307-
if envCfg.TaskBrokerServerURI != tt.envVars[EnvVarTaskBrokerServerURI] {
308-
t.Errorf("FromEnv() TaskBrokerServerURI = %v, want %v", envCfg.TaskBrokerServerURI, tt.envVars[EnvVarTaskBrokerServerURI])
309-
}
310-
311-
if envCfg.RunnerServerURI != tt.envVars[EnvVarRunnerServerURI] {
312-
t.Errorf("FromEnv() RunnerServerURI = %v, want %v", envCfg.RunnerServerURI, tt.envVars[EnvVarRunnerServerURI])
320+
if !reflect.DeepEqual(envCfg, tt.expected) {
321+
t.Errorf("FromEnv() = %+v, want %+v", envCfg, tt.expected)
313322
}
314323

315324
if os.Getenv(EnvVarRunnerServerEnabled) != "true" {

0 commit comments

Comments
 (0)