@@ -8,7 +8,15 @@ module AutoSource
88 module_function
99
1010 def enabled?
11- ENV [ 'AUTO_SOURCE_ENABLED' ] == 'true'
11+ # Enable by default in development, require explicit setting in production
12+ rack_env = ENV [ 'RACK_ENV' ]
13+ auto_source_enabled = ENV [ 'AUTO_SOURCE_ENABLED' ]
14+
15+ if rack_env == 'development'
16+ auto_source_enabled != 'false'
17+ else
18+ auto_source_enabled == 'true'
19+ end
1220 end
1321
1422 def authenticate ( request )
@@ -18,13 +26,24 @@ def authenticate(request)
1826 credentials = Base64 . decode64 ( auth [ 6 ..] ) . split ( ':' )
1927 username , password = credentials
2028
21- username == ENV [ 'AUTO_SOURCE_USERNAME' ] &&
22- password == ENV [ 'AUTO_SOURCE_PASSWORD' ]
29+ # Use default credentials in development if not set
30+ expected_username = ENV [ 'AUTO_SOURCE_USERNAME' ] || ( ENV [ 'RACK_ENV' ] == 'development' ? 'admin' : nil )
31+ expected_password = ENV [ 'AUTO_SOURCE_PASSWORD' ] || ( ENV [ 'RACK_ENV' ] == 'development' ? 'password' : nil )
32+
33+ return false unless expected_username && expected_password
34+
35+ username == expected_username && password == expected_password
2336 end
2437
2538 def allowed_origin? ( request )
2639 origin = request . env [ 'HTTP_HOST' ] || request . env [ 'HTTP_X_FORWARDED_HOST' ]
27- allowed_origins = ( ENV [ 'AUTO_SOURCE_ALLOWED_ORIGINS' ] || '' ) . split ( ',' ) . map ( &:strip )
40+
41+ # In development, allow localhost origins by default
42+ if ENV [ 'RACK_ENV' ] == 'development'
43+ allowed_origins = ( ENV [ 'AUTO_SOURCE_ALLOWED_ORIGINS' ] || 'localhost:3000,localhost:3001,127.0.0.1:3000,127.0.0.1:3001' ) . split ( ',' ) . map ( &:strip )
44+ else
45+ allowed_origins = ( ENV [ 'AUTO_SOURCE_ALLOWED_ORIGINS' ] || '' ) . split ( ',' ) . map ( &:strip )
46+ end
2847
2948 allowed_origins . empty? || allowed_origins . include? ( origin )
3049 end
0 commit comments