@@ -55,12 +55,13 @@ defmodule Mix.Tasks.Beacon.Gen.Site do
55
55
|> create_migration ( repo )
56
56
|> add_use_beacon_in_router ( router )
57
57
|> add_beacon_pipeline_in_router ( router )
58
- |> mount_site_in_router ( router , site , path , web_module )
58
+ |> mount_site_in_router ( router , site , path , host )
59
59
|> add_site_config_in_config_runtime ( site , repo , router , host )
60
60
|> add_beacon_config_in_app_supervisor ( site , repo , router )
61
61
|> maybe_create_proxy_endpoint ( host )
62
62
|> maybe_create_new_endpoint ( host , otp_app , web_module )
63
63
|> maybe_configure_new_endpoint ( host , otp_app )
64
+ |> maybe_add_new_endpoint_to_application ( host , repo )
64
65
|> Igniter . add_notice ( """
65
66
Site #{ inspect ( site ) } generated successfully.
66
67
@@ -141,7 +142,7 @@ defmodule Mix.Tasks.Beacon.Gen.Site do
141
142
)
142
143
end
143
144
144
- defp mount_site_in_router ( igniter , router , site , path , web_module ) do
145
+ defp mount_site_in_router ( igniter , router , site , path , host ) do
145
146
case Igniter.Project.Module . find_module ( igniter , router ) do
146
147
{ :ok , { _igniter , _source , zipper } } ->
147
148
exists? =
@@ -156,16 +157,17 @@ defmodule Mix.Tasks.Beacon.Gen.Site do
156
157
"Site already exists: #{ site } , skipping creation."
157
158
)
158
159
else
159
- Igniter.Libs.Phoenix . append_to_scope (
160
- igniter ,
161
- "/" ,
160
+ content =
162
161
"""
163
162
beacon_site #{ inspect ( path ) } , site: #{ inspect ( site ) }
164
- """ ,
165
- with_pipelines: [ :browser , :beacon ] ,
166
- router: router ,
167
- arg2: web_module
168
- )
163
+ """
164
+
165
+ opts =
166
+ if host ,
167
+ do: [ with_pipelines: [ :browser , :beacon ] , router: router , arg2: [ host: host ] ] ,
168
+ else: [ with_pipelines: [ :browser , :beacon ] , router: router ]
169
+
170
+ Igniter.Libs.Phoenix . append_to_scope ( igniter , "/" , content , opts )
169
171
end
170
172
171
173
_ ->
@@ -364,6 +366,12 @@ defmodule Mix.Tasks.Beacon.Gen.Site do
364
366
)
365
367
end
366
368
369
+ defp maybe_add_new_endpoint_to_application ( igniter , nil , _ ) , do: igniter
370
+
371
+ defp maybe_add_new_endpoint_to_application ( igniter , host , repo ) do
372
+ Igniter.Project.Application . add_new_child ( igniter , new_endpoint_module ( igniter , host ) , after: repo )
373
+ end
374
+
367
375
defp new_endpoint_module ( igniter , host ) do
368
376
[ implicit_prefix | _ ] = String . split ( host , "." )
369
377
Igniter.Libs.Phoenix . web_module_name ( igniter , "#{ String . capitalize ( implicit_prefix ) } Endpoint" )
0 commit comments