@@ -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:
@@ -408,6 +409,10 @@ defmodule Lightning.Config.Bootstrap do
408409 config :logger , :level , log_level
409410 end
410411
412+ if log_level == :debug do
413+ config :libcluster , debug: true
414+ end
415+
411416 database_url = env! ( "DATABASE_URL" , :string , nil )
412417
413418 config :lightning , Lightning.Repo ,
@@ -418,7 +423,6 @@ defmodule Lightning.Config.Bootstrap do
418423 queue_interval: env! ( "DATABASE_QUEUE_INTERVAL" , :integer , 1000 )
419424
420425 host = env! ( "URL_HOST" , :string , "example.com" )
421- port = env! ( "PORT" , :integer , 4000 )
422426 url_port = env! ( "URL_PORT" , :integer , 443 )
423427
424428 config :lightning ,
@@ -464,18 +468,6 @@ defmodule Lightning.Config.Bootstrap do
464468 You can generate one by calling: mix phx.gen.secret
465469 """
466470
467- listen_address =
468- env! (
469- "LISTEN_ADDRESS" ,
470- fn address ->
471- address
472- |> String . split ( "." )
473- |> Enum . map ( & String . to_integer / 1 )
474- |> List . to_tuple ( )
475- end ,
476- { 127 , 0 , 0 , 1 }
477- )
478-
479471 origins =
480472 env! (
481473 "ORIGINS" ,
@@ -490,40 +482,10 @@ defmodule Lightning.Config.Bootstrap do
490482
491483 url_scheme = env! ( "URL_SCHEME" , :string , "https" )
492484
493- idle_timeout =
494- env! (
495- "IDLE_TIMEOUT" ,
496- fn str ->
497- case Integer . parse ( str ) do
498- :error -> 60_000
499- { val , _ } -> val * 1_000
500- end
501- end ,
502- 60_000
503- )
504-
505485 config :lightning , LightningWeb.Endpoint ,
506486 url: [ host: host , port: url_port , scheme: url_scheme ] ,
507487 secret_key_base: secret_key_base ,
508488 check_origin: origins ,
509- http: [
510- ip: listen_address ,
511- port: port ,
512- compress: true ,
513- protocol_options: [
514- # Note that if a request is more than 10x the max dataclip size, we cut
515- # the connection immediately to prevent memory issues via the
516- # :max_skip_body_length setting.
517- max_skip_body_length:
518- Application . get_env (
519- :lightning ,
520- :max_dataclip_size_bytes ,
521- 10_000_000
522- ) *
523- 10 ,
524- idle_timeout: idle_timeout
525- ]
526- ] ,
527489 server: true
528490 end
529491
@@ -539,6 +501,8 @@ defmodule Lightning.Config.Bootstrap do
539501 assert_receive_timeout: env! ( "ASSERT_RECEIVE_TIMEOUT" , :integer , 1000 )
540502 end
541503
504+ config :lightning , LightningWeb.Endpoint , http: http_config ( config_env ( ) )
505+
542506 config :sentry ,
543507 dsn: env! ( "SENTRY_DSN" , :string , nil ) ,
544508 filter: Lightning.SentryEventFilter ,
@@ -814,4 +778,69 @@ defmodule Lightning.Config.Bootstrap do
814778 value -> value
815779 end
816780 end
781+
782+ defp http_config ( env , opts \\ [ ] )
783+ # Production environment configuration
784+ defp http_config ( :prod , opts ) do
785+ port = Keyword . get ( opts , :port ) || env! ( "PORT" , :integer , 4000 )
786+
787+ listen_address =
788+ env! (
789+ "LISTEN_ADDRESS" ,
790+ fn address ->
791+ address
792+ |> String . split ( "." )
793+ |> Enum . map ( & String . to_integer / 1 )
794+ |> List . to_tuple ( )
795+ end ,
796+ { 127 , 0 , 0 , 1 }
797+ )
798+
799+ idle_timeout =
800+ env! (
801+ "IDLE_TIMEOUT" ,
802+ fn str ->
803+ case Integer . parse ( str ) do
804+ :error -> 60_000
805+ { val , _ } -> val * 1_000
806+ end
807+ end ,
808+ 60_000
809+ )
810+
811+ [
812+ ip: listen_address ,
813+ port: port ,
814+ compress: true ,
815+ protocol_options: [
816+ # Note that if a request is more than 10x the max dataclip size, we cut
817+ # the connection immediately to prevent memory issues via the
818+ # :max_skip_body_length setting.
819+ max_skip_body_length:
820+ Application . get_env (
821+ :lightning ,
822+ :max_dataclip_size_bytes ,
823+ 10_000_000
824+ ) * 10 ,
825+ idle_timeout: idle_timeout
826+ ]
827+ ]
828+ end
829+
830+ # Default configuration for non-production environments
831+ defp http_config ( _env , opts ) do
832+ port =
833+ Keyword . get ( opts , :port ) ||
834+ env! (
835+ "PORT" ,
836+ :integer ,
837+ get_env ( :lightning , [ LightningWeb.Endpoint , :http , :port ] )
838+ )
839+
840+ [
841+ ip: { 0 , 0 , 0 , 0 } ,
842+ port: port ,
843+ compress: true
844+ ]
845+ end
817846end
0 commit comments