@@ -34,7 +34,7 @@ public static IResourceBuilder<NgrokResource> AddNgrok(
34
34
ArgumentNullException . ThrowIfNull ( builder ) ;
35
35
if ( configurationFolder is not null )
36
36
ArgumentException . ThrowIfNullOrWhiteSpace ( configurationFolder ) ;
37
-
37
+
38
38
if ( endpointPort is not null )
39
39
{
40
40
ArgumentOutOfRangeException . ThrowIfLessThan ( endpointPort . Value , 1 , nameof ( endpointPort ) ) ;
@@ -49,28 +49,27 @@ public static IResourceBuilder<NgrokResource> AddNgrok(
49
49
configurationFolder ??= Path . Combine ( builder . AppHostDirectory , ".ngrok" ) ;
50
50
if ( ! Directory . Exists ( configurationFolder ) )
51
51
Directory . CreateDirectory ( configurationFolder ) ;
52
-
53
- var resource = new NgrokResource ( name ) ;
54
- var resourceBuilder = builder . AddResource ( resource )
52
+
53
+ var resourceBuilder = builder . AddResource ( new NgrokResource ( name ) )
55
54
. WithImage ( NgrokContainerValues . Image , NgrokContainerValues . Tag )
56
55
. WithImageRegistry ( NgrokContainerValues . Registry )
57
56
. WithBindMount ( configurationFolder , "/var/tmp/ngrok" )
58
57
. WithHttpEndpoint ( targetPort : 4040 , port : endpointPort , name : endpointName ) ;
59
- builder . Eventing . Subscribe < AfterEndpointsAllocatedEvent > ( async ( e , ct ) =>
58
+ resourceBuilder . OnResourceEndpointsAllocated ( async ( resource , e , ct ) =>
60
59
{
61
60
var endpointTuples = resource . Annotations
62
61
. OfType < NgrokEndpointAnnotation > ( )
63
62
. SelectMany ( annotation => annotation . Endpoints . Select ( ngrokEndpoint => ( endpointRefernce : annotation . Resource . GetEndpoint ( ngrokEndpoint . EndpointName ) , ngrokEndpoint ) ) )
64
63
. ToList ( ) ;
65
64
await CreateNgrokConfigurationFileAsync ( configurationFolder , name , endpointTuples , configurationVersion ?? 3 ) ;
66
-
65
+
67
66
resourceBuilder . WithArgs (
68
- "start" , endpointTuples . Count > 0 ? "--all" : "--none" ,
67
+ "start" , endpointTuples . Count > 0 ? "--all" : "--none" ,
69
68
"--config" , $ "/var/tmp/ngrok/{ name } .yml") ;
70
69
} ) ;
71
70
return resourceBuilder ;
72
71
}
73
-
72
+
74
73
/// <summary>
75
74
/// Adds a ngrok auth token to a ngrok resource.
76
75
/// </summary>
@@ -86,7 +85,7 @@ public static IResourceBuilder<NgrokResource> WithAuthToken(
86
85
87
86
return builder . WithEnvironment ( NgrokContainerValues . AuthTokenEnvName , ngrokAuthToken ) ;
88
87
}
89
-
88
+
90
89
/// <summary>
91
90
/// Adds a ngrok auth token to a ngrok resource.
92
91
/// </summary>
@@ -102,13 +101,13 @@ public static IResourceBuilder<NgrokResource> WithAuthToken(
102
101
103
102
return builder . WithEnvironment ( NgrokContainerValues . AuthTokenEnvName , ngrokAuthToken ) ;
104
103
}
105
-
104
+
106
105
/// <summary>
107
106
/// Configures a resource with endpoints as a ngrok tunnel endpoint.
108
107
/// </summary>
109
108
/// <typeparam name="TResource">The resource type.</typeparam>
110
109
public static IResourceBuilder < NgrokResource > WithTunnelEndpoint < TResource > (
111
- this IResourceBuilder < NgrokResource > builder ,
110
+ this IResourceBuilder < NgrokResource > builder ,
112
111
IResourceBuilder < TResource > resource ,
113
112
string endpointName ,
114
113
string ? ngrokUrl = null ,
@@ -136,7 +135,7 @@ public static IResourceBuilder<NgrokResource> WithTunnelEndpoint<TResource>(
136
135
137
136
return builder ;
138
137
}
139
-
138
+
140
139
private static async Task CreateNgrokConfigurationFileAsync (
141
140
string configurationFolder ,
142
141
string name ,
@@ -165,7 +164,7 @@ private static async Task CreateNgrokConfigurationFileAsync(
165
164
break ;
166
165
case 3 :
167
166
ngrokConfig . AppendLine ( "agent:" ) ;
168
- ngrokConfig . AppendLine ( " log: stdout" ) ;
167
+ ngrokConfig . AppendLine ( " log: stdout" ) ;
169
168
if ( endpointTuples . Count > 0 )
170
169
{
171
170
ngrokConfig . AppendLine ( ) ;
@@ -190,7 +189,7 @@ private static async Task CreateNgrokConfigurationFileAsync(
190
189
private static string GetUpstreamUrl ( EndpointReference endpoint )
191
190
{
192
191
var isLocal = endpoint . Host . Equals ( "localhost" , StringComparison . InvariantCultureIgnoreCase ) ;
193
- var host = ( IsWindows || IsOsx ) && isLocal ? "host.docker.internal" : endpoint . Host ;
192
+ var host = ( IsWindows || IsOsx ) && isLocal ? "host.docker.internal" : endpoint . Host ;
194
193
return $ "{ endpoint . Scheme } ://{ host } :{ endpoint . Port } ";
195
194
}
196
195
}
0 commit comments