@@ -114,7 +114,8 @@ defmodule Lightning.Config.Bootstrap do
114114 "RTM" ,
115115 & Utils . ensure_boolean / 1 ,
116116 Utils . get_env ( [ :lightning , Lightning.Runtime.RuntimeManager , :start ] )
117- )
117+ ) ,
118+ port: env! ( "RTM_PORT" , :integer , 2222 )
118119
119120 config :lightning , :workers ,
120121 private_key:
@@ -407,6 +408,10 @@ defmodule Lightning.Config.Bootstrap do
407408 config :logger , :level , log_level
408409 end
409410
411+ if log_level == :debug do
412+ config :libcluster , debug: true
413+ end
414+
410415 database_url = env! ( "DATABASE_URL" , :string , nil )
411416
412417 config :lightning , Lightning.Repo ,
@@ -417,7 +422,6 @@ defmodule Lightning.Config.Bootstrap do
417422 queue_interval: env! ( "DATABASE_QUEUE_INTERVAL" , :integer , 1000 )
418423
419424 host = env! ( "URL_HOST" , :string , "example.com" )
420- port = env! ( "PORT" , :integer , 4000 )
421425 url_port = env! ( "URL_PORT" , :integer , 443 )
422426
423427 config :lightning ,
@@ -463,18 +467,6 @@ defmodule Lightning.Config.Bootstrap do
463467 You can generate one by calling: mix phx.gen.secret
464468 """
465469
466- listen_address =
467- env! (
468- "LISTEN_ADDRESS" ,
469- fn address ->
470- address
471- |> String . split ( "." )
472- |> Enum . map ( & String . to_integer / 1 )
473- |> List . to_tuple ( )
474- end ,
475- { 127 , 0 , 0 , 1 }
476- )
477-
478470 origins =
479471 env! (
480472 "ORIGINS" ,
@@ -489,40 +481,10 @@ defmodule Lightning.Config.Bootstrap do
489481
490482 url_scheme = env! ( "URL_SCHEME" , :string , "https" )
491483
492- idle_timeout =
493- env! (
494- "IDLE_TIMEOUT" ,
495- fn str ->
496- case Integer . parse ( str ) do
497- :error -> 60_000
498- { val , _ } -> val * 1_000
499- end
500- end ,
501- 60_000
502- )
503-
504484 config :lightning , LightningWeb.Endpoint ,
505485 url: [ host: host , port: url_port , scheme: url_scheme ] ,
506486 secret_key_base: secret_key_base ,
507487 check_origin: origins ,
508- http: [
509- ip: listen_address ,
510- port: port ,
511- compress: true ,
512- protocol_options: [
513- # Note that if a request is more than 10x the max dataclip size, we cut
514- # the connection immediately to prevent memory issues via the
515- # :max_skip_body_length setting.
516- max_skip_body_length:
517- Application . get_env (
518- :lightning ,
519- :max_dataclip_size_bytes ,
520- 10_000_000
521- ) *
522- 10 ,
523- idle_timeout: idle_timeout
524- ]
525- ] ,
526488 server: true
527489 end
528490
@@ -538,6 +500,8 @@ defmodule Lightning.Config.Bootstrap do
538500 assert_receive_timeout: env! ( "ASSERT_RECEIVE_TIMEOUT" , :integer , 1000 )
539501 end
540502
503+ config :lightning , LightningWeb.Endpoint , http: http_config ( config_env ( ) )
504+
541505 config :sentry ,
542506 dsn: env! ( "SENTRY_DSN" , :string , nil ) ,
543507 filter: Lightning.SentryEventFilter ,
@@ -811,4 +775,69 @@ defmodule Lightning.Config.Bootstrap do
811775 value -> value
812776 end
813777 end
778+
779+ defp http_config ( env , opts \\ [ ] )
780+ # Production environment configuration
781+ defp http_config ( :prod , opts ) do
782+ port = Keyword . get ( opts , :port ) || env! ( "PORT" , :integer , 4000 )
783+
784+ listen_address =
785+ env! (
786+ "LISTEN_ADDRESS" ,
787+ fn address ->
788+ address
789+ |> String . split ( "." )
790+ |> Enum . map ( & String . to_integer / 1 )
791+ |> List . to_tuple ( )
792+ end ,
793+ { 127 , 0 , 0 , 1 }
794+ )
795+
796+ idle_timeout =
797+ env! (
798+ "IDLE_TIMEOUT" ,
799+ fn str ->
800+ case Integer . parse ( str ) do
801+ :error -> 60_000
802+ { val , _ } -> val * 1_000
803+ end
804+ end ,
805+ 60_000
806+ )
807+
808+ [
809+ ip: listen_address ,
810+ port: port ,
811+ compress: true ,
812+ protocol_options: [
813+ # Note that if a request is more than 10x the max dataclip size, we cut
814+ # the connection immediately to prevent memory issues via the
815+ # :max_skip_body_length setting.
816+ max_skip_body_length:
817+ Application . get_env (
818+ :lightning ,
819+ :max_dataclip_size_bytes ,
820+ 10_000_000
821+ ) * 10 ,
822+ idle_timeout: idle_timeout
823+ ]
824+ ]
825+ end
826+
827+ # Default configuration for non-production environments
828+ defp http_config ( _env , opts ) do
829+ port =
830+ Keyword . get ( opts , :port ) ||
831+ env! (
832+ "PORT" ,
833+ :integer ,
834+ get_env ( :lightning , [ LightningWeb.Endpoint , :http , :port ] )
835+ )
836+
837+ [
838+ ip: { 0 , 0 , 0 , 0 } ,
839+ port: port ,
840+ compress: true
841+ ]
842+ end
814843end
0 commit comments