-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract sdk from client, add aspnetcore extension
- Loading branch information
1 parent
7955830
commit f0e6330
Showing
20 changed files
with
252 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<PackageId>Tunnelite.AspNetCore</PackageId> | ||
<PackageTags>tunnel;tunneling;websockets;signalr;reverse-proxy;proxy;</PackageTags> | ||
<Authors>Cristi Pufu</Authors> | ||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
<RepositoryType>git</RepositoryType> | ||
<PackageReadmeFile>README.md</PackageReadmeFile> | ||
<Description>SDK for tunneling AspNetCore apps</Description> | ||
<PackageProjectUrl>https://github.com/cristipufu/ws-tunnel-signalr</PackageProjectUrl> | ||
<RepositoryUrl>https://github.com/cristipufu/ws-tunnel-signalr</RepositoryUrl> | ||
<Version>1.0.0</Version> | ||
<IsPackable>true</IsPackable> | ||
<IncludeSymbols>true</IncludeSymbols> | ||
<SymbolPackageFormat>snupkg</SymbolPackageFormat> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\README.md"> | ||
<Pack>True</Pack> | ||
<PackagePath>\</PackagePath> | ||
</None> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<FrameworkReference Include="Microsoft.AspNetCore.App" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Tunnelite.Sdk\Tunnelite.Sdk.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting.Server; | ||
using Microsoft.AspNetCore.Hosting.Server.Features; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Tunnelite.Sdk; | ||
|
||
#nullable disable | ||
namespace Tunnelite.AspNetCore; | ||
|
||
public static class TunneliteExtensions | ||
{ | ||
private static readonly Guid ClientId = Guid.NewGuid(); | ||
|
||
public static IApplicationBuilder UseTunnelite(this IApplicationBuilder app) | ||
{ | ||
var lifetime = app.ApplicationServices.GetRequiredService<IHostApplicationLifetime>(); | ||
var server = app.ApplicationServices.GetRequiredService<IServer>(); | ||
|
||
lifetime.ApplicationStarted.Register(() => | ||
{ | ||
var addressFeature = server.Features.Get<IServerAddressesFeature>(); | ||
var localUrl = addressFeature?.Addresses.FirstOrDefault(); | ||
if (string.IsNullOrEmpty(localUrl)) | ||
{ | ||
throw new InvalidOperationException("Unable to determine the local URL of the application."); | ||
} | ||
Task.Run(async () => | ||
{ | ||
var httpTunnel = new HttpTunnelRequest | ||
{ | ||
ClientId = ClientId, | ||
LocalUrl = localUrl, | ||
PublicUrl = "https://tunnelite.com", | ||
}; | ||
var client = new HttpTunnelClient(httpTunnel, null); | ||
client.Log += x => Console.WriteLine(x); | ||
client.LogRequest += (method, path) => Console.WriteLine($"{DateTimeOffset.Now:HH:mm:ss} [{method}]: {path}"); | ||
client.LogFailedRequest += (method, path) => Console.Write($"{DateTimeOffset.Now:HH:mm:ss} [{method}]: {path}"); | ||
client.LogError += x => Console.WriteLine(x); | ||
client.LogException += x => Console.WriteLine(x.Message); | ||
await client.ConnectAsync(); | ||
LogTunnelInfo(client.TunnelUrl); | ||
}, CancellationToken.None); | ||
}); | ||
|
||
return app; | ||
} | ||
|
||
private static void LogTunnelInfo(string tunnelUrl) | ||
{ | ||
Console.WriteLine(); | ||
Console.ForegroundColor = ConsoleColor.Cyan; | ||
Console.WriteLine("╔══════════════════════════════════════════════════════════════════════════════╗"); | ||
Console.WriteLine($" Tunnelite URL: {tunnelUrl,-67}"); | ||
Console.WriteLine("╚══════════════════════════════════════════════════════════════════════════════╝"); | ||
Console.ResetColor(); | ||
Console.WriteLine(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...elite.Client/HttpTunnel/HttpConnection.cs → ...unnelite.Sdk/HttpTunnel/HttpConnection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.